Submission #2121540


Source Code Expand

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 100000000
typedef pair<ll, ll> P;



//initialization here
//
const int maxn = 1e5+10;
int b[maxn];
int ima[maxn];
map<int,int> m;  //単語iにはkステップ目でいます
//
//initialization finish


// your function is here
//




//
// your function finished



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// your code is here
	//
	int n, a; cin >> n >> a;
	string k; cin >> k;
	FOR(i, 1, n + 1) cin >> b[i];
	int oria = a;
	ima[0] = a;
	m[a] = 0;
	int start, loop;
	FOR(i, 1, n + 1)
	{
		a = b[a];
		ima[i] = a;

		if (m[a]||a==oria)
		{
			start = m[a];
			loop = i - m[a];
			break;
		}
		else {
			m[a] = i;
		}
	}

	if (k.size() < 7) //閉ループに入らない可能性
	{
		int ss = stoi(k);
		rep(tmp, ss) oria = b[oria];
		Print(oria);
	}
	else
	{
		int modk = 0;
		rep(i, k.size())
		{
			modk = (modk * 10 + (k[i] - '0')) % loop;
		}

		modk -= start;
		if (modk < 0) modk += loop;

		Print(ima[start + modk]);

	}


	//
	// your code finished


	return 0;
}

Submission Info

Submission Time
Task D - へんてこ辞書
User sawakee
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2316 Byte
Status WA
Exec Time 10 ms
Memory 848 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 0 / 50 0 / 50
Status
AC × 2
AC × 7
WA × 5
AC × 18
WA × 7
Set Name Test Cases
Sample subtask0_sample_01.txt, subtask0_sample_03.txt
Subtask1 subtask0_0.txt, subtask0_1.txt, subtask0_2.txt, subtask0_3.txt, subtask0_4.txt, subtask0_5.txt, subtask0_6.txt, subtask0_7.txt, subtask0_8.txt, subtask0_9.txt, subtask0_sample_01.txt, subtask0_sample_03.txt
All subtask0_0.txt, subtask0_1.txt, subtask0_2.txt, subtask0_3.txt, subtask0_4.txt, subtask0_5.txt, subtask0_6.txt, subtask0_7.txt, subtask0_8.txt, subtask0_9.txt, subtask0_sample_01.txt, subtask0_sample_03.txt, subtask1_0.txt, subtask1_1.txt, subtask1_10.txt, subtask1_11.txt, subtask1_2.txt, subtask1_3.txt, subtask1_4.txt, subtask1_5.txt, subtask1_6.txt, subtask1_7.txt, subtask1_8.txt, subtask1_9.txt, subtask1_sample_02.txt
Case Name Status Exec Time Memory
subtask0_0.txt WA 8 ms 640 KB
subtask0_1.txt AC 7 ms 512 KB
subtask0_2.txt AC 8 ms 640 KB
subtask0_3.txt AC 6 ms 512 KB
subtask0_4.txt WA 8 ms 640 KB
subtask0_5.txt WA 7 ms 512 KB
subtask0_6.txt AC 6 ms 512 KB
subtask0_7.txt WA 8 ms 640 KB
subtask0_8.txt WA 6 ms 512 KB
subtask0_9.txt AC 8 ms 640 KB
subtask0_sample_01.txt AC 1 ms 256 KB
subtask0_sample_03.txt AC 1 ms 256 KB
subtask1_0.txt AC 7 ms 640 KB
subtask1_1.txt WA 8 ms 768 KB
subtask1_10.txt AC 10 ms 848 KB
subtask1_11.txt AC 1 ms 256 KB
subtask1_2.txt WA 7 ms 640 KB
subtask1_3.txt AC 6 ms 640 KB
subtask1_4.txt AC 7 ms 640 KB
subtask1_5.txt AC 9 ms 768 KB
subtask1_6.txt AC 7 ms 720 KB
subtask1_7.txt AC 6 ms 640 KB
subtask1_8.txt AC 9 ms 768 KB
subtask1_9.txt AC 9 ms 768 KB
subtask1_sample_02.txt AC 1 ms 256 KB