Submission #201781

# Submission time Handle Problem Language Result Execution time Memory
201781 2020-02-12T01:49:05 Z EmmanuelAC Političari (COCI20_politicari) C++14
65 / 70
29 ms 2424 KB
#include <bits/stdc++.h>
#define ll long long
#define REP(i,n) for(int i=0; i<n; i++)
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
using namespace std;

long long N, K;
int Mat[1000][1000];
map< pii, int> MAP;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> K;
    REP(i, N)
        REP(j, N)
            cin >> Mat[i][j];

    K-= 2;
    pii par = mp(1, 2);
    //cout  << "PAR: " << par.fi << " " << par.se << "\n";
    long long Time = 0;
    while(K > 0 && MAP.find(par)==MAP.end()){
        MAP[par] = Time++;
        int prev = par.se;
        int curr = Mat[par.se-1][par.fi-1];
        par = mp(prev, curr);
        //cout  << "PAR: " << par.fi << " " << par.se << "\n";
        K--;
    }

    //cout << "FISH " << K << "\n";
    //return 0;

    if(K == 0){
        cout << par.se << "\n";
        return 0;
    }

    //cout << "KK: " << K << "\n";

    long long l = Time - MAP[par];
    //cout << "L = " << l << "\n";
    K -= (K/l)*l;

    //cout << "K = " << K << "\n";
    while(K > 0){
        int prev = par.se;
        int curr = Mat[par.se-1][par.fi-1];
        par = mp(prev, curr);
        //cout  << "PAR: " << par.fi << " " << par.se << "\n";
        K--;
    }

    cout << par.se << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 504 KB Execution killed with signal 8 (could be triggered by violating memory limits)
2 Correct 8 ms 1272 KB Output is correct
3 Correct 17 ms 1912 KB Output is correct
4 Correct 20 ms 2040 KB Output is correct
5 Correct 29 ms 2296 KB Output is correct
6 Correct 23 ms 2424 KB Output is correct
7 Correct 4 ms 376 KB Output is correct
8 Correct 6 ms 888 KB Output is correct
9 Correct 9 ms 1272 KB Output is correct
10 Correct 20 ms 2168 KB Output is correct
11 Correct 23 ms 2292 KB Output is correct
12 Correct 25 ms 2296 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 6 ms 888 KB Output is correct