답안 #218149

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
218149 2020-04-01T10:24:56 Z Vimmer Političari (COCI20_politicari) C++14
70 / 70
34 ms 6528 KB
#include <bits/stdc++.h>

#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 200005
#define M ll(1000000007)

using namespace std;

typedef long long ll;

ll in[1000][1000], a[1001][1001];

int main()
{
    //freopen("mining.in","r",stdin); freopen("mining.out","w",stdout);
    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    ll n, k;

    cin >> n >> k;

    if (k == 1) {cout << 1 << endl; exit(0);}

    for (ll i = 1; i <= n; i++)
        for (ll j = 1; j <= n; j++) cin >> a[i][j];

    k--; k--;

    ll nxt = 2, tp = 1, lst = 1;

    while (k > 0)
    {
        ll nt = nxt;

        nxt = a[nxt][lst];

        lst = nt;

        if (in[nxt][lst] != 0 && k % (tp - in[nxt][lst]) != 0)  k %= (tp - in[nxt][lst]);

        in[nxt][lst] = tp;

        tp++;

        k--;
    }

    cout << nxt << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 9 ms 2816 KB Output is correct
3 Correct 19 ms 4716 KB Output is correct
4 Correct 21 ms 5504 KB Output is correct
5 Correct 34 ms 6116 KB Output is correct
6 Correct 25 ms 5888 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 6 ms 1408 KB Output is correct
9 Correct 10 ms 2944 KB Output is correct
10 Correct 22 ms 5376 KB Output is correct
11 Correct 24 ms 6528 KB Output is correct
12 Correct 25 ms 6392 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 6 ms 1536 KB Output is correct