Submission #1302838
Source Code Expand
#include <bits/stdc++.h> using namespace std; #define REP(i, s, n) for(int i = s; i < n; ++i) #define rep(i, n) REP(i, 0, n) #define SORT(c) sort((c).begin(), (c).end()) #define IINF INT_MAX #define LLINF LLONG_MAX #define DEBUG false typedef long long ll; typedef pair <int, int> ii; int main() { int n, a; ll k2 = LLINF; string k; cin >> n >> a >> k; vector<int> b(n+1); REP(i, 1, n + 1) cin >> b[i]; if(k.size() < 7) k2 = stoi(k); vector<int> used; if(DEBUG) cout << n << endl << a << endl << k2 <<endl; if(DEBUG) REP(i, 1, n+1) cout << b[i] << endl; int word = a; int cycle; ll cnt = 0; vector<int>::iterator it; used.push_back(word); while(1){ cnt++; word = b[word]; if(DEBUG) cout << word << endl; if(cnt == k2){ cout << word << endl; return 0; } it = find(used.begin(), used.end(), word); if(it != used.end()){ cycle = used.size() - distance(used.begin(), it); break; } used.push_back(word); } if(DEBUG) cout << endl; if(DEBUG) rep(i, used.size()) cout << used[i] << endl; if(DEBUG) cout << endl; int rem = 0; rep(i, k.size()){ int tmp = (int)(k[i] - '0') + rem * 10; rem = tmp % cycle; } if(DEBUG) cout << rem << "\t" << cycle << "\t" << cnt << endl << endl; //cout << *it << endl << endl; //it = it + ((rem + cycle - cnt) % cycle); it = it + (((k2 % cycle) + cycle - cnt) % cycle); cout << *it << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - 有向グラフ |
User | letter |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1492 Byte |
Status | WA |
Exec Time | 1 ms |
Memory | 256 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 100 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | subtask0_sample_01.txt, subtask0_sample_02.txt, subtask0_sample_03.txt, subtask0_sample_04.txt |
All | subtask0_sample_01.txt, subtask0_sample_02.txt, subtask0_sample_03.txt, subtask0_sample_04.txt, subtask1_manual01.txt, subtask1_manual02.txt, subtask1_manual03.txt, subtask1_manual04.txt, subtask1_manual05.txt, subtask1_manual06.txt, subtask1_manual07.txt, subtask1_manual08.txt, subtask1_random01.txt, subtask1_random02.txt, subtask1_random03.txt, subtask1_random04.txt, subtask1_random05.txt, subtask1_special01.txt, subtask1_special02.txt, subtask1_special03.txt, subtask1_special04.txt, subtask1_special05.txt, subtask1_special06.txt, subtask1_special07.txt, subtask1_special08.txt, subtask1_special09.txt, subtask1_special10.txt, subtask1_special11.txt, subtask1_special12.txt, subtask1_special13.txt, subtask1_special14.txt, subtask1_special15.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
subtask0_sample_01.txt | WA | 1 ms | 256 KB |
subtask0_sample_02.txt | WA | 1 ms | 256 KB |
subtask0_sample_03.txt | WA | 1 ms | 256 KB |
subtask0_sample_04.txt | WA | 1 ms | 256 KB |
subtask1_manual01.txt | WA | 1 ms | 256 KB |
subtask1_manual02.txt | WA | 1 ms | 256 KB |
subtask1_manual03.txt | WA | 1 ms | 256 KB |
subtask1_manual04.txt | WA | 1 ms | 256 KB |
subtask1_manual05.txt | WA | 1 ms | 256 KB |
subtask1_manual06.txt | WA | 1 ms | 256 KB |
subtask1_manual07.txt | WA | 1 ms | 256 KB |
subtask1_manual08.txt | WA | 1 ms | 256 KB |
subtask1_random01.txt | WA | 1 ms | 256 KB |
subtask1_random02.txt | WA | 1 ms | 256 KB |
subtask1_random03.txt | WA | 1 ms | 256 KB |
subtask1_random04.txt | WA | 1 ms | 256 KB |
subtask1_random05.txt | WA | 1 ms | 256 KB |
subtask1_special01.txt | WA | 1 ms | 256 KB |
subtask1_special02.txt | WA | 1 ms | 256 KB |
subtask1_special03.txt | WA | 1 ms | 256 KB |
subtask1_special04.txt | WA | 1 ms | 256 KB |
subtask1_special05.txt | WA | 1 ms | 256 KB |
subtask1_special06.txt | WA | 1 ms | 256 KB |
subtask1_special07.txt | WA | 1 ms | 256 KB |
subtask1_special08.txt | WA | 1 ms | 256 KB |
subtask1_special09.txt | WA | 1 ms | 256 KB |
subtask1_special10.txt | WA | 1 ms | 256 KB |
subtask1_special11.txt | WA | 1 ms | 256 KB |
subtask1_special12.txt | WA | 1 ms | 256 KB |
subtask1_special13.txt | WA | 1 ms | 256 KB |
subtask1_special14.txt | WA | 1 ms | 256 KB |
subtask1_special15.txt | WA | 1 ms | 256 KB |