답안 #849205

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
849205 2023-09-14T09:13:23 Z vjudge1 Političari (COCI20_politicari) C++17
35 / 70
14 ms 4260 KB
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define int long long
#define pii pair<int,int>
#define piii pair<int, pair<int, int>>
#define v(int) vector<int>
#define si size()
#define foe(i,a,b) for(int i=a;i<=b;++i)
#define fol(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define Bit(mask,i) (1<<i)&mask
#define offBit(mask,i) (1<<i)^mask
#define onBit(mask,i) (1<<i)mask
#define CNT(x) __builtin_popcountll(x)
const int mod = 1e9+7;
const int base = 2309;
const int inf = 1e18;
const int N = 1e6+10;
const int LG = 20;
// ▄  ▄ ▄  ▄ ▄  ▄ ▄  ▄ ▄  ▄ ▄▄ ▄ ▄▄▄▄
// █▄▄█ █  █ █  █ █▄▄█ █  █ ██ █ █ ▄▄
// █  █ █▄▄█ █▄▄█ █  █ █▄▄█ █ ██ █▄▄█

int n, k;
int a[510][510];
int dem = 2;
int ans = 2;
v(pii) save;
int dd[510][510];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    foe(i,1,n)
    {
        foe(j,1,n)
        {
            cin >> a[i][j];
        }
    }
    if(k == 1)
    {
        cout << 1;
        return 0;
    }
    if(k == 2)
    {
        cout << 2;
        return 0;
    }
    if(k <= 1e5)
    {
        int i = 2;
        int j = 1;
        while(dem < k)
        {
    //        cout << i << " " << j << "\n";
            ans = a[i][j];
            int x = i;
            int y = j;
            i = a[x][y];
            j = x;
            ++ dem;
        }
        cout << ans;
    }
    else
    {
        int i = 2;
        int j = 1;
        dd[i][j] = 1;
        while(dem < k)
        {
            save.pb({i, j});
            int x = i;
            int y = j;
            i = a[x][y];
            j = x;
            ++ dem;
            if(dd[i][j] == 1)
            {
                break;
            }
            else
                dd[i][j] = 1;
        }
        k -= 2;
        k %= save.si;
        if(k == 0)
            k = save.si;
        k -= 1;
        ans = a[save[k].fi][save[k].se];
        cout << ans;
    }
    cerr << "\n" << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 3 ms 3160 KB Output isn't correct
3 Incorrect 8 ms 3932 KB Output isn't correct
4 Incorrect 13 ms 4188 KB Output isn't correct
5 Incorrect 12 ms 4188 KB Output isn't correct
6 Incorrect 14 ms 4188 KB Output isn't correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 3 ms 3164 KB Output is correct
10 Correct 11 ms 3932 KB Output is correct
11 Correct 13 ms 4260 KB Output is correct
12 Correct 13 ms 4188 KB Output is correct
13 Incorrect 1 ms 2396 KB Output isn't correct
14 Incorrect 1 ms 2908 KB Output isn't correct