Submission #883810

#TimeUsernameProblemLanguageResultExecution timeMemory
883810vjudge1Političari (COCI20_politicari)C++17
70 / 70
239 ms124660 KiB
#include <bits/stdc++.h> using namespace std; #define sp << " " << #define int long long #define vi vector<int> #define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++) #define pii pair<int,int> void solve() { int n,k; cin >> n >> k; vector<vi> a(n+1,vi(n+1)); F(i,n) F(j,n) cin >> a[i][j]; if (k == 1) { cout << 1 << endl; return; } int up[n*n+1][62]; memset(up,0,sizeof up); F(i,n) { F(j,n) { if (i == j) continue; int idx = (i-1)*n+j; up[idx][0] = (a[i][j]-1)*n+i; } } for (int i=1;i<62;i++) { for (int j=1;j<=n*n;j++) { up[j][i] = up[up[j][i-1]][i-1]; } } int ans = n+1; for (int i=0;i<62;i++) { if ((k-2)&(1LL<<i)) ans = up[ans][i]; } cout << (ans+n-1)/n << endl; } signed main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #ifdef Local freopen("in","r",stdin); freopen("out","w",stdout); #endif int t = 1; //cin >> t; F(i,t) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...