# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
732250 | 2023-04-28T19:55:52 Z | vjudge1 | Političari (COCI20_politicari) | C++17 | 17 ms | 2696 KB |
#include<bits/stdc++.h> #define int long long #define MOD 1000000007 #define all(x) x.begin(),x.end() #define ff first #define ss second #define pb push_back #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); using namespace std; int32_t main(){ fast; int n,k; cin>>n>>k; if(k==1){ cout<<"1"<<endl; return 0; } if(k==2){ cout<<"2"<<endl; return 0; } k-=2; set<pair<int,int>>s; vector<pair<int,int>>v; int arr[n+5][n+5]; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++)cin>>arr[i][j]; } int x=1,y=2; while(1){ if(s.count({x,y}))break; s.insert({x,y}); v.pb({x,y}); int z=x; x=y; y=arr[y][z]; } if(k<v.size()){ cout<<v[k].ss<<endl; return 0; } vector<int>v2; for(int i=0;i<v.size();i++){ if(v[i]==make_pair(x,y)){ k-=i; for(int j=i;j<v.size();j++){ v2.pb(v[j].ss); } break; } } cout<<v2[k%(v2.size())]<<endl; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 4 ms | 840 KB | Output is correct |
3 | Correct | 10 ms | 1868 KB | Output is correct |
4 | Correct | 13 ms | 2276 KB | Output is correct |
5 | Correct | 15 ms | 2632 KB | Output is correct |
6 | Correct | 17 ms | 2628 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 2 ms | 452 KB | Output is correct |
9 | Correct | 5 ms | 980 KB | Output is correct |
10 | Correct | 13 ms | 2260 KB | Output is correct |
11 | Correct | 16 ms | 2644 KB | Output is correct |
12 | Correct | 16 ms | 2696 KB | Output is correct |
13 | Correct | 1 ms | 320 KB | Output is correct |
14 | Correct | 2 ms | 468 KB | Output is correct |