답안 #201069

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201069 2020-02-09T09:35:55 Z mraron Političari (COCI20_politicari) C++14
10 / 70
31 ms 3448 KB
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=3.1415926535897932384626433832795;
const ll INF = 1LL<<62;
const ll MINF = -1LL<<62;

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)

ll n,k;
ll t[501][501];
ll volt[501][501];




int main() {
	IO;
	cin>>n>>k;
	for(int i=1;i<=n;++i) {
		for(int j=1;j<=n;++j) {
			cin>>t[i][j];
		}
	}

	if(k==1) cout<<"1\n";
	else if(k==2) cout<<"2\n";
	else {
		ll ind=3;
		pair<int,int> state={1,2};
		k-=2;

		while(k>0) {	
			state.xx=t[state.yy][state.xx];
			swap(state.xx,state.yy);
			k--;
			if(volt[state.xx][state.yy]) {
				break ;
			}
			volt[state.xx][state.yy]=ind++;
		}

		if(k==0) {
			cout<<state.yy<<"\n";
		}else {
			ll cycle=ind-volt[state.xx][state.yy];
			cerr<<cycle<<"\n";
			k%=cycle;
			while(k>0) {	
				state.xx=t[state.yy][state.xx];
				swap(state.xx,state.yy);
				k--;
			}
		
			cout<<state.yy<<"\n";
		}
	}
	
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Incorrect 9 ms 2040 KB Output isn't correct
3 Incorrect 17 ms 2680 KB Output isn't correct
4 Incorrect 22 ms 2936 KB Output isn't correct
5 Incorrect 26 ms 3192 KB Output isn't correct
6 Incorrect 31 ms 2936 KB Output isn't correct
7 Correct 5 ms 376 KB Output is correct
8 Incorrect 6 ms 1144 KB Output isn't correct
9 Incorrect 10 ms 2168 KB Output isn't correct
10 Incorrect 21 ms 2808 KB Output isn't correct
11 Incorrect 24 ms 3448 KB Output isn't correct
12 Incorrect 24 ms 3320 KB Output isn't correct
13 Incorrect 5 ms 636 KB Output isn't correct
14 Incorrect 6 ms 1272 KB Output isn't correct