제출 #282568

#제출 시각아이디문제언어결과실행 시간메모리
282568AMO5Političari (COCI20_politicari)C++17
10 / 70
21 ms3072 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define eb emplace_back #define mt make_tuple #define all(x) (x).begin(), (x).end() #define sz(x) int(x.size()) #define MOD 1000000007 typedef long long ll; typedef pair <int, int> ii; typedef pair <ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef long double ld; const ll INF=63; const int mxn=505; bool DEBUG=0; int n,a[mxn][mxn],vis[mxn][mxn]; ll k; int main() { ios_base::sync_with_stdio(0); cin.tie(0); //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); cin>>n>>k; for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ cin>>a[i][j]; } } if(k==1){ cout<<1<<"\n"; return 0; } if(k==2){ cout<<2<<"\n"; return 0; } int ptr=3,now=2,prev=1; vi list; while(!vis[now][prev]){ //cerr<<ptr<<" "<<now<<" "<<prev<<"\n"; vis[now][prev]=ptr; int pr = now; now=a[now][prev]; prev = pr; if(ptr==k){ cout<<now<<"\n"; return 0; } ptr++; list.eb(now); } //cerr<<ptr<<"\n"; k-=vis[now][prev]; ll siz = 1LL*(ptr-vis[now][prev]); k=k%siz; cout<<list[k]; return 0; } // READ & UNDERSTAND // ll, int overflow, array bounds, memset(0) // special cases (n=1?), n+1 (1-index) // do smth instead of nothing & stay organized // WRITE STUFF DOWN
#Verdict Execution timeMemoryGrader output
Fetching results...