Submission #350008

#TimeUsernameProblemLanguageResultExecution timeMemory
350008arnold518Političari (COCI20_politicari)C++14
70 / 70
31 ms4076 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 500; const ll MAXK = 1e18; int N; ll K; int A[MAXN+10][MAXN+10]; int P[MAXN*MAXN+10]; int vis[MAXN*MAXN+10]; int f(int x) { int ret=x%N; if(ret==0) ret+=N; return ret; } int main() { scanf("%d%lld", &N, &K); for(int i=1; i<=N; i++) { for(int j=1; j<=N; j++) { scanf("%d", &A[i][j]); int u=N*(j-1)+i; int v=N*(i-1)+A[i][j]; P[u]=v; } } if(K==1) return !printf("1\n"); int now=2; for(int i=2; i<K; i++) { if(vis[now]) { int cyc=i-vis[now]; while(1) { if(vis[now]%cyc==K%cyc) return !printf("%d\n", f(now)); now=P[now]; } return 0; } else { vis[now]=i; now=P[now]; } } printf("%d\n", f(now)); }

Compilation message (stderr)

politicari.cpp: In function 'int main()':
politicari.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |  scanf("%d%lld", &N, &K);
      |  ~~~~~^~~~~~~~~~~~~~~~~~
politicari.cpp:32:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   32 |    scanf("%d", &A[i][j]);
      |    ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...