| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 201013 | dolphingarlic | Političari (COCI20_politicari) | C++14 | 25 ms | 1656 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;
int a[501][501], nxt[501][501];
bool visited[501][501];
vector<int> tail, cycle;
int main() {
iostream::sync_with_stdio(false);
cin.tie(0);
int n;
ll m;
cin >> n >> m;
FOR(i, 1, n + 1) FOR(j, 1, n + 1) cin >> a[i][j];
pair<int, int> curr = {1, 2};
while (true) {
if (visited[curr.second][curr.first]) {
pair<int, int> here = {1, 2};
tail.push_back(1);
while (here != curr) {
tail.push_back(here.second);
here = {here.second, a[here.second][here.first]};
}
cycle.push_back(here.second);
here = {here.second, a[here.second][here.first]};
while (here != curr) {
cycle.push_back(here.second);
here = {here.second, a[here.second][here.first]};
}
break;
} else {
visited[curr.second][curr.first] = true;
curr = {curr.second, a[curr.second][curr.first]};
}
}
if (m <= tail.size()) cout << tail[m - 1];
else cout << cycle[(m - tail.size() - 1) % cycle.size()];
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
