답안 #583644

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
583644 2022-06-25T20:01:05 Z AGE Političari (COCI20_politicari) C++14
60 / 70
52 ms 4180 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[1000][1000];
map<pair<int,int>,int>viss;
vector<pair<int,int>>v;
pair<int,int>anss;
main()
{
    v.clear();
    viss.clear();

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

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

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

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

    while(1){

        int x=v.size()-1;

        if(viss[{v[x].S,a[v[x].S][v[x].F]}]==1){
            anss.F=v[x].S;
            anss.S=a[v[x].S][v[x].F];
            break;
        }


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

    }

    int ok=0;
    reverse(v.begin(),v.end());
    while((v.back().F!=anss.F||v.back().S!=anss.S)&&m>0)
         v.pop_back(),m--;

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

    if(m==0){

        cout<<v[m].S<<endl;
        return 0;

    }
    int xx=m%v.size();

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

    xx--;

    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()
      | ^~~~
politicari.cpp: In function 'int main()':
politicari.cpp:46:9: warning: unused variable 'ok' [-Wunused-variable]
   46 |     int ok=0;
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Correct 10 ms 1492 KB Output is correct
3 Correct 31 ms 3020 KB Output is correct
4 Correct 40 ms 3648 KB Output is correct
5 Correct 50 ms 4156 KB Output is correct
6 Correct 50 ms 4172 KB Output is correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Correct 5 ms 980 KB Output is correct
9 Correct 16 ms 1620 KB Output is correct
10 Correct 46 ms 3596 KB Output is correct
11 Correct 52 ms 4180 KB Output is correct
12 Correct 51 ms 4132 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 5 ms 980 KB Output is correct