답안 #849344

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
849344 2023-09-14T14:03:10 Z LTTrungCHL Političari (COCI20_politicari) C++17
10 / 70
14 ms 3628 KB
///***LTT***///
/// ->TUYEN QUOC GIA<- ///
#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("popcnt")
#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define CHECKBIT(mask,i) ((mask>>(i) )&1) // == 1 la bat, == 0 la tat
#define OFFBIT(mask,i) ((1<<(i))^mask) // tat bit thu i
#define ONBIT(mask,i) ((1<<(i))mask) // bat bit thu i
using namespace std;
const long long oo = 1e9+7;
const int N = 2 * 1e5 + 10;
int n, a[505][505],  k;
vector <int> ans;
bool dd[505][505];
void inp(){
    cin >> n >> k;
    for (int i = 1;i <= n;i++){
        for (int j = 1;j <= n;j++){
            cin >> a[i][j];
        }
    }
    return;
}
void solve(){
    ans.pb(1);
    ans.pb(2);
    int tt = 2;
    int p = 1;
    int u = 2;
    int preu = u;
    int prep = p;
    while (!dd[u][p] and tt <= k){
        dd[u][p] = true;
        preu = u;
        prep = p;
        u = a[preu][prep];
        p = preu;
        if (dd[u][p]) break;
        ans.pb(u);
        ++tt;
    }
    ans.pop_back();
//    for (int i = 0;i < ans.size();i++){
//        cout << ans[i] <<"\n";
//    }
    int sz = ans.size();
    int o = k % sz;
    if (o == 0) o = sz;
    cout  << ans[o - 1];
    return;
}
signed main(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    if (fopen("file.inp", "r")){
        freopen("file.inp", "r", stdin);
        freopen("file.out", "w", stdout);
    }
    //int t;
    //cin >> t;
    //while(t--){
    inp();
    solve();
    //}
}



Compilation message

politicari.cpp: In function 'int main()':
politicari.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen("file.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
politicari.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen("file.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 3 ms 2648 KB Output isn't correct
3 Incorrect 8 ms 3164 KB Output isn't correct
4 Incorrect 10 ms 3416 KB Output isn't correct
5 Incorrect 14 ms 3628 KB Output isn't correct
6 Incorrect 12 ms 3420 KB Output isn't correct
7 Correct 1 ms 2392 KB Output is correct
8 Incorrect 1 ms 2392 KB Output isn't correct
9 Incorrect 3 ms 2648 KB Output isn't correct
10 Incorrect 10 ms 3420 KB Output isn't correct
11 Incorrect 12 ms 3416 KB Output isn't correct
12 Incorrect 12 ms 3416 KB Output isn't correct
13 Incorrect 1 ms 2392 KB Output isn't correct
14 Incorrect 1 ms 2648 KB Output isn't correct