답안 #501330

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
501330 2022-01-02T19:47:05 Z inksamurai Političari (COCI20_politicari) C++17
45 / 70
15 ms 4548 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define crep(i,x,n) for(int i=x;i<n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define vec(...) vector<__VA_ARGS__>
#define _3qplfh5 ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
using pii=pair<int,int>;
using vi=vector<int>;
using vll=vector<long long>;

int main(){
_3qplfh5;
	int n,k;
	cin>>n>>k;
	vec(vi) a(n,vi(n));
	rep(i,n){
		rep(j,n){
			cin>>a[i][j];
			a[i][j]--;
		}
	}
	k--;
	vec(vi) usd(n,vi(n));
	vec(pii) way;
	int c=0,nec=1;
	way.pb({c,nec});
	usd[c][nec]=1;
	vec(pii) incyc;
	while(k>0){
		int onec=nec;
		// nec , a[nec][c]
		int nxt=a[nec][c];
		// printf("%d %d\n", nec,nxt);
		if(usd[nec][nxt]){
			pii p={nec,nxt};
			while(sz(way)){
				incyc.pb(way.back());
				if(way.back()==p){
					break;
				}
				way.pop_back();
			}
			break;
		}
		way.pb({nec,nxt});
		usd[nec][nxt]=1;
		nec=a[nec][c];
		c=onec;
		k--;
	}
	if(k==0){
		printf("%d\n", c+1);
		exit(0);
	}
	reverse(all(incyc));
	k--;
	k%=sz(incyc);
	printf("%d\n", incyc[k].fi+1);
//	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 308 KB Output is correct
2 Runtime error 1 ms 1228 KB Execution killed with signal 11
3 Runtime error 3 ms 3012 KB Execution killed with signal 11
4 Runtime error 4 ms 3788 KB Execution killed with signal 11
5 Runtime error 5 ms 4544 KB Execution killed with signal 11
6 Runtime error 6 ms 4548 KB Execution killed with signal 11
7 Correct 0 ms 204 KB Output is correct
8 Correct 2 ms 452 KB Output is correct
9 Correct 4 ms 840 KB Output is correct
10 Correct 13 ms 2624 KB Output is correct
11 Correct 15 ms 3140 KB Output is correct
12 Correct 15 ms 3116 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 460 KB Output is correct