제출 #1300098

#제출 시각아이디문제언어결과실행 시간메모리
1300098khoianhLabels (NOI20_labels)C++20
100 / 100
36 ms9464 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int mn = 3e5 + 5; ll n, a[mn], b[mn], f[mn]; pair<ll, ll> l, r; void solve(){ cin >> n; for(int i = 1; i <= n; ++i) f[i] = 0; for(int i = 2; i <= n; ++i) cin >> b[i]; l.second = r.second = 1; l.first = r.first = 0; ll cur = 0; for(int i = 2; i <= n; ++i){ cur += b[i]; l = max(l, {cur, i}); r = min(r, {cur, i}); } a[l.second] = 1 + l.first - r.first; if(a[l.second] != n){ cout << -1; return; } a[r.second] = 1; if(l.second < r.second){ for(int i = l.second - 1; i >= 1; --i) a[i] = a[i + 1] - b[i + 1]; for(int i = r.second - 1; i > l.second; --i) a[i] = a[i + 1] - b[i + 1]; for(int i = r.second + 1; i <= n; ++i) a[i] = b[i] + a[i - 1]; } else { for(int i = r.second - 1; i >= 1; --i) a[i] = a[i + 1] - b[i + 1]; for(int i = l.second - 1; i > r.second; --i) a[i] = a[i + 1] - b[i + 1]; for(int i = l.second + 1; i <= n; ++i) a[i] = b[i] + a[i - 1]; } for(int i = 1; i <= n; ++i){ if(a[i] < 1 || a[i] > n){ cout << -1; return; } } for(int i = 2; i <= n; ++i){ if(a[i] - a[i - 1] != b[i]){ cout << -1; return; } } for(int i = 1; i <= n; ++i) cout << a[i] << " "; return; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); if(fopen(".INP", "r")) { freopen(".INP", "r", stdin); freopen(".OUT", "w", stdout); } int testCase = 1; //cin >> testCase; while(testCase--) solve(); }

컴파일 시 표준 에러 (stderr) 메시지

Labels.cpp: In function 'int main()':
Labels.cpp:55:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |                 freopen(".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~
Labels.cpp:56:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |                 freopen(".OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#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...