Submission #503509

#TimeUsernameProblemLanguageResultExecution timeMemory
503509brayden04Labels (NOI20_labels)C++14
47 / 100
1091 ms4548 KiB
#include <bits/stdc++.h> #define endl '\n' #define int long long using namespace std; int N = 0; vector<int> D; bool dp(int A1, int Di){ 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); cin >> N; for (int i = 0; i < N-1; i++){ int temp = 0; cin >> temp; D.push_back(temp); } int possibleAns = -1; for (int i = 1; i <= N; i++){ bool test = dp(i, 0); int A = i; if (test == false){ continue; } else{ if (possibleAns != -1){ cout << -1 << endl; return 0; } else{ possibleAns = i; } } } int A = possibleAns; for (int i = 0; i < N-1; i++){ cout << A << " "; A += D[i]; } cout << A << endl; /* if (D[0] == 1){ cout << "1 2" << endl; } else if (D[0] == -1){ cout << "2 1" << endl; } else{ cout << "-1" << endl; } */ }

Compilation message (stderr)

Labels.cpp: In function 'int main()':
Labels.cpp:35:9: warning: unused variable 'A' [-Wunused-variable]
   35 |     int A = i;
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...