Submission #201040

# Submission time Handle Problem Language Result Execution time Memory
201040 2020-02-09T07:19:34 Z gs14004 Političari (COCI20_politicari) C++17
70 / 70
101 ms 59120 KB
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using namespace std;
using pi = pair<int, int>;
using lint = long long;
const int MAXN = 250005;
 
int n; lint k;
int nxt[66][MAXN];
 
int main(){
    scanf("%d %lld",&n,&k);
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            int x; scanf("%d",&x);
            if(x){
                x--;
                nxt[0][i * n + j] = x * n + i;
            }
        }
    }
    int pos = n;
    k--;
    for(int i=1; i<60; i++){
        for(int j=0; j<n*n; j++){
            nxt[i][j] = nxt[i-1][nxt[i-1][j]];
        }
    }
    for(int i=0; i<60; i++){
        if(k & 1) pos = nxt[i][pos];
        k >>= 1;
    }
    cout << (pos % n) + 1 << endl;
}

Compilation message

politicari.cpp: In function 'int main()':
politicari.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %lld",&n,&k);
     ~~~~~^~~~~~~~~~~~~~~~~
politicari.cpp:16:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             int x; scanf("%d",&x);
                    ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 632 KB Output is correct
2 Correct 18 ms 11640 KB Output is correct
3 Correct 61 ms 37624 KB Output is correct
4 Correct 69 ms 48120 KB Output is correct
5 Correct 86 ms 59000 KB Output is correct
6 Correct 101 ms 59000 KB Output is correct
7 Correct 6 ms 760 KB Output is correct
8 Correct 10 ms 4856 KB Output is correct
9 Correct 23 ms 13176 KB Output is correct
10 Correct 79 ms 48120 KB Output is correct
11 Correct 90 ms 59120 KB Output is correct
12 Correct 89 ms 58976 KB Output is correct
13 Correct 6 ms 1272 KB Output is correct
14 Correct 11 ms 4856 KB Output is correct