답안 #311678

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
311678 2020-10-10T23:37:24 Z MilosMilutinovic Labels (NOI20_labels) C++14
0 / 100
221 ms 34024 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i];
  }
  int sum = 0;
  vector<int> b;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] == 0) {
      cout << -1 << '\n';
      return 0;
    }
    sum += a[i];
    b.push_back(sum);
  }
  map<int, int> mp;
  for (int i = 0; i < n - 1; i++) {
    /*if (b[i] > n || mp[b[i]]) {
      cout << -1 << '\n';
      return 0;
    }*/
    mp[b[i]] = 1;
  }
  int st = n - *max_element(b.begin(), b.end());
  vector<int> ans;
  ans.push_back(st);
  for (int i = 0; i < n - 1; i++) {
    ans.push_back(ans.back() + a[i]);
  }
  map<int, int> cnt;
  for (int c : ans) {
    cnt[c]++;
  }
  int new_cnt = 0;
  for (int i = 1; i <= n; i++) {
    new_cnt += cnt[i];
  }
  if (new_cnt != n || cnt[n] == 0) {
    cout << -1 << '\n';
    return 0;
  }
  for (int c : ans) {
    cout << c << " ";
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 221 ms 34024 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Incorrect 198 ms 32104 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -