답안 #583610

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
583610 2022-06-25T18:39:22 Z AGE Političari (COCI20_politicari) C++14
55 / 70
59 ms 3712 KB
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define int long long
using namespace std;
const int N=1e6,M=2e3,mod=1e9+7;
int a[510][510];
map<pair<int,int>,int>vis;
vector<pair<int,int>>v;
pair<int,int>ans;
main()
{
    v.clear();
    ans={0,0};
    vis.clear();

    int n,m;
    cin>>n>>m;

    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cin>>a[i][j];

    v.pb({0,1});
    v.pb({1,2});

    vis[{0,1}]=1;
    vis[{1,2}]=1;

    while(1){

        int x=v.size()-1;

        if(vis[{v[x].S,a[v[x].S-1][v[x].F-1]}]==1){
            ans.F=v[x].S;
            ans.S=a[v[x].S-1][v[x].F-1];
            break;
        }


        vis[{v[x].S,a[v[x].S-1][v[x].F-1]}]=1;
        v.pb({v[x].S,a[v[x].S-1][v[x].F-1]});

    }


    reverse(v.begin(),v.end());
    while((v.size())&&((*v.rbegin()).F!=ans.F||(*v.rbegin()).S!=ans.S)&&m>0)
        v.pop_back(),m--;


    reverse(v.begin(),v.end());

    int xx=m%v.size();

    if(xx==0)
        xx=v.size();

    xx--;

    assert(v[xx].S>10);
    cout<<v[xx].S<<endl;

    return 0;
}

Compilation message

politicari.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main()
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Correct 12 ms 1220 KB Output is correct
3 Runtime error 32 ms 3712 KB Execution killed with signal 6
4 Correct 51 ms 1988 KB Output is correct
5 Correct 57 ms 2208 KB Output is correct
6 Correct 59 ms 2252 KB Output is correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Correct 4 ms 724 KB Output is correct
9 Correct 15 ms 1172 KB Output is correct
10 Correct 54 ms 2068 KB Output is correct
11 Correct 52 ms 2204 KB Output is correct
12 Correct 48 ms 2252 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 3 ms 852 KB Output is correct