답안 #732256

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
732256 2023-04-28T20:29:37 Z vjudge1 Političari (COCI20_politicari) C++17
70 / 70
24 ms 4244 KB
// author: MisterReaper (Ahmet Alp Orakci)
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int) x.size()
#define ONLINE_JUDGE

#ifndef ONLINE_JUDGE
    #include "debug.h"
    #define OPEN freopen(".in", "r", stdin); freopen(".out", "w", stdout);
    #define TIME cerr << "\n" << fixed << setprecision(2) << 1000.0 * clock() / CLOCKS_PER_SEC << " milliseconds ";
#else
    #define debug(...) void(23)
    #define OPEN void(0000)
    #define TIME void(232323233)
#endif

void solve()
{
    int n, k; cin >> n >> k;
    int arr[n +1][n +1], vis[n +1][n +1];
    memset(vis, -1, sizeof(vis));

    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            cin >> arr[j][i];
        }
    }

    vector <int> v;
    v.emplace_back(1);
    v.emplace_back(2);

    while(true)
    {
        if(vis[v[sz(v) - 2]][v.back()] != -1) break;
        vis[v[sz(v) - 2]][v.back()] = sz(v) -2;

        v.emplace_back(arr[v[sz(v) - 2]][v.back()]);
    }

    debug(v);

    if(k < sz(v))
    {
        cout << v[k -1];
        return;
    }

    k -= vis[v[sz(v) -2]][v.back()];

    vector <int> ans;
    for(int i = vis[v[sz(v) -2]][v.back()]; i < sz(v) -2; i++) ans.emplace_back(v[i]);

    debug(ans);

    k %= sz(ans);
    cout << ans[(k -1 + sz(ans)) % sz(ans)];
    
    return;
}

int32_t main()
{
    OPEN;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int t = 1; //cin >> t;
    while(t--)
    {
        solve();
    }

    TIME;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 4 ms 980 KB Output is correct
3 Correct 11 ms 2772 KB Output is correct
4 Correct 14 ms 3504 KB Output is correct
5 Correct 16 ms 4180 KB Output is correct
6 Correct 19 ms 4180 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 4 ms 1108 KB Output is correct
10 Correct 17 ms 3428 KB Output is correct
11 Correct 24 ms 4236 KB Output is correct
12 Correct 17 ms 4244 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 596 KB Output is correct