Submission #749927

# Submission time Handle Problem Language Result Execution time Memory
749927 2023-05-29T01:28:40 Z Trunkty Političari (COCI20_politicari) C++14
70 / 70
239 ms 128432 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll

int n,k;
int jump[250005][65];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    if(k<=2){
        cout << k << "\n";
        return 0;
    }
    k -= 2;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            int a;
            cin >> a;
            if(a){
                jump[(i-1)*n+(j-1)][0] = (a-1)*n+(i-1);
            }
        }
    }
    for(int j=1;j<=63;j++){
        for(int i=0;i<n*n;i++){
            jump[i][j] = jump[jump[i][j-1]][j-1];
        }
    }
    int curr = 1*n+0;
    for(int j=63;j>=0;j--){
        if(k&(1LL<<j)){
            curr = jump[curr][j];
        }
    }
    cout << curr/n+1 << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 30 ms 24344 KB Output is correct
3 Correct 132 ms 81036 KB Output is correct
4 Correct 191 ms 104088 KB Output is correct
5 Correct 239 ms 128432 KB Output is correct
6 Correct 223 ms 128428 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 9 ms 9520 KB Output is correct
9 Correct 30 ms 27656 KB Output is correct
10 Correct 187 ms 104092 KB Output is correct
11 Correct 222 ms 128312 KB Output is correct
12 Correct 231 ms 128348 KB Output is correct
13 Correct 1 ms 1620 KB Output is correct
14 Correct 9 ms 9556 KB Output is correct