답안 #201267

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201267 2020-02-10T05:22:38 Z smjleo Političari (COCI20_politicari) C++14
70 / 70
25 ms 2424 KB
#pragma region cp-helper
#include <bits/stdc++.h>
using namespace std;
#define AC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define lll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vll vector<lll>
#define vvl vector<vl>
#define vii vector<ii>
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(a, b)
#define umap unordered_map
#define uset unordered_set
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
#define qmod %mod
#define pls int
#define give main()
const int mod = 1000000007;
#pragma endregion

const int N = 5*1e2+5;

ll n, k, g[N][N], offset, endi;
vi ans = {1};
map<lll, ll> m;

void dfs(ll prev, ll node, ll index) {
    if (m.find({prev, node}) != m.end()) {
        offset = m[{prev, node}];
        endi = index;
        return;
    }
    m[{prev, node}] = index;
    ans.pb(node);
    dfs(node, g[node][prev], index+1);
}

pls give {
    AC;
    cin >> n >> k;
    for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) cin >> g[i][j];
    for (int i=1; i<=n; i++) {
        if (g[1][i] == 2) m[{i, 1}] = 1;
    }
    dfs(1, 2, 2);
    if (k <= offset) cout << ans[k-1] << nl;
    else cout << ans[offset + ((k-offset) % (endi-offset))-1];
}

Compilation message

politicari.cpp:1:0: warning: ignoring #pragma region cp [-Wunknown-pragmas]
 #pragma region cp-helper
 
politicari.cpp:30:0: warning: ignoring #pragma endregion  [-Wunknown-pragmas]
 #pragma endregion
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 9 ms 1144 KB Output is correct
3 Correct 17 ms 1912 KB Output is correct
4 Correct 20 ms 2168 KB Output is correct
5 Correct 24 ms 2424 KB Output is correct
6 Correct 25 ms 2400 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 6 ms 888 KB Output is correct
9 Correct 10 ms 1272 KB Output is correct
10 Correct 19 ms 2168 KB Output is correct
11 Correct 23 ms 2424 KB Output is correct
12 Correct 25 ms 2296 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 6 ms 888 KB Output is correct