Submission #320462

#TimeUsernameProblemLanguageResultExecution timeMemory
320462egasLabels (NOI20_labels)C++14
100 / 100
271 ms29016 KiB
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n; cin >> n; vector<long long> a(n-1); for(long long i = 0 ; i < n-1 ; i++) { cin >> a[i]; } vector<long long> pref; pref.push_back(a[0]); for(long long i=1; i<n-1; i++) { pref.push_back(pref.back()+a[i]); } long long maxi = *max_element(pref.begin(),pref.end()); long long mini = *max_element(pref.begin(),pref.end()); long long xo=min(n,n-maxi); bool hoga=true; if(maxi+xo<1 or maxi+xo>n or mini+xo<1 or mini+xo>n) hoga=false; vector<long long> res; res.push_back(xo); map<long long,long long> freq; freq[xo]=1; for(long long i=0; i<n-1; i++) { res.push_back(res.back()+a[i]); freq[res.back()]++; } if(freq[1]==0 or freq[n]==0)hoga=false; for(long long i = 0 ; i < res.size() ; i++) { if(res[i]<1 or res[i]>n)hoga=false; } if(hoga) { for(auto t : res )cout<<t<<" "; cout << '\n'; } else { cout << -1 << '\n'; } return 0; }

Compilation message (stderr)

Labels.cpp: In function 'int32_t main()':
Labels.cpp:63:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     for(long long i = 0 ; i < res.size() ; 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...