Submission #383323

#TimeUsernameProblemLanguageResultExecution timeMemory
383323MODDILabels (NOI20_labels)C++14
0 / 100
96 ms4828 KiB
#include <bits/stdc++.h> #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define vi vector<int> #define vl vector<ll> #define mp make_pair #define pb push_back using namespace std; int n; vi d, pref; bool check(int mid){ for(int i = 0; i < pref.size(); i++){ if(pref[i] + mid <= n && pref[i] + mid > 0) continue; else{ return false; } } return true; } int main(){ cin>>n; for(int i = 0; i < n-1; i++){ int a; cin>>a; d.pb(a); } pref.pb(d[0]); for(int i = 1; i < n - 1; i++) pref.pb(d[i] + pref[i-1]); int l = 1, r = n, mid, smallest_working = 1e9, biggest_working = 0; while(l <= r){ mid = (l + r) / 2; //cout<<mid<<endl; bool works = check(mid); if(works){ smallest_working = min(smallest_working, mid); biggest_working = max(biggest_working, mid); //cout<<mid<<endl; l = mid + 1; } else r = mid - 1; } //cout<<smallest_working<<" "<<biggest_working<<endl; if(smallest_working != biggest_working) cout<<-1<<endl; else{ for(int i = 0; i < n; i++) { if(i == 0) cout<<smallest_working<<" "; else cout<<pref[i-1] + smallest_working<<" "; } } return 0; }

Compilation message (stderr)

Labels.cpp: In function 'bool check(int)':
Labels.cpp:13:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |  for(int i = 0; i < pref.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...