답안 #949484

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
949484 2024-03-19T09:31:46 Z MilosMilutinovic 빌딩 장식 3 (JOI15_building3) C++14
100 / 100
70 ms 21184 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> b(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> b[i];
  }
  vector<int> mx(n - 1);
  vector<bool> good(n - 1);
  for (int i = 0; i < n - 1; i++) {
    mx[i] = (i == 0 ? b[i] : max(mx[i - 1], b[i]));
    if (i == 0) {
      good[i] = (b[i] == 1); 
    } else {
      good[i] = (good[i - 1] & (b[i] <= mx[i - 1] + 1));
    }
  }
  long long ans = 0;
  {
    vector<int> seq;
    seq.push_back(1);
    for (int i = 0; i < n - 1; i++) {
      seq.push_back(b[i]);
    }
    bool ok = (seq[0] == 1);
    int mx = 1;
    for (int i = 1; i < n; i++) {
      if (seq[i] > mx + 1) {
        ok = false;
        break;
      }
      mx = max(mx, seq[i]);
    }
    ans += ok;
  }
  set<int> st;
  for (int i = n - 1; i >= 1; i--) {
    if (good[i - 1] && (int) st.size() < 2) {
      if ((int) st.size() == 1) {
        int x = *st.begin();
        if (b[i - 1] != x && x <= mx[i - 1] + 1) {
          ans += 1;
        }
      } else {
        int c = mx[i - 1] + 1;
        if (b[i - 1] <= c) {
          c -= 1;
        }
        ans += c;
      }
    }
    if (i > 1 && b[i - 1] > mx[i - 2] + 1) {
      st.insert(b[i - 1] - 1);
    }
  }
  cout << ans << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 456 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 456 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 65 ms 17860 KB Output is correct
22 Correct 59 ms 16624 KB Output is correct
23 Correct 59 ms 18116 KB Output is correct
24 Correct 70 ms 19824 KB Output is correct
25 Correct 70 ms 19908 KB Output is correct
26 Correct 70 ms 21184 KB Output is correct
27 Correct 70 ms 19316 KB Output is correct
28 Correct 70 ms 19572 KB Output is correct
29 Correct 48 ms 15100 KB Output is correct
30 Correct 58 ms 17924 KB Output is correct
31 Correct 61 ms 17140 KB Output is correct
32 Correct 61 ms 18628 KB Output is correct
33 Correct 63 ms 17396 KB Output is correct
34 Correct 62 ms 18672 KB Output is correct
35 Correct 70 ms 20980 KB Output is correct