#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
int N = 0;
vector<int> D;
bool visited[1000005];
bool dp(int A1, int Di){
if (visited[A1] == true) return false;
visited[A1] = true;
if (Di == N-1){
return true;
}
int A2 = A1 + D[Di];
if (A2 <= 0 || A2 > N) return false;
return dp(A2, Di+1);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
memset(visited, false, sizeof(visited));
cin >> N;
for (int i = 0; i < N-1; i++){
int temp = 0;
cin >> temp;
D.push_back(temp);
}
for (int i = 1; i <= N; i++){
memset(visited, false, sizeof(visited));
bool test = dp(i, 0);
int A = i;
if (test == false){
continue;
}
else{
for (int i = 0; i < N-1; i++){
cout << A << " ";
A += D[i];
}
cout << A << endl;
return 0;
}
}
cout << "-1" << endl;
/*
if (D[0] == 1){
cout << "1 2" << endl;
}
else if (D[0] == -1){
cout << "2 1" << endl;
}
else{
cout << "-1" << endl;
}
*/
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1228 KB |
Output is correct |
2 |
Correct |
1 ms |
1228 KB |
Output is correct |
3 |
Correct |
1 ms |
1228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1228 KB |
Output is correct |
2 |
Correct |
1 ms |
1228 KB |
Output is correct |
3 |
Correct |
1 ms |
1228 KB |
Output is correct |
4 |
Correct |
1 ms |
1228 KB |
Output is correct |
5 |
Incorrect |
1 ms |
1228 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1228 KB |
Output is correct |
2 |
Correct |
1 ms |
1228 KB |
Output is correct |
3 |
Correct |
1 ms |
1228 KB |
Output is correct |
4 |
Correct |
1 ms |
1228 KB |
Output is correct |
5 |
Incorrect |
1 ms |
1228 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
5680 KB |
Output is correct |
2 |
Correct |
1 ms |
1228 KB |
Output is correct |
3 |
Execution timed out |
1082 ms |
5436 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1228 KB |
Output is correct |
2 |
Correct |
1 ms |
1228 KB |
Output is correct |
3 |
Correct |
1 ms |
1228 KB |
Output is correct |
4 |
Correct |
1 ms |
1228 KB |
Output is correct |
5 |
Incorrect |
1 ms |
1228 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |