Submission #600557

# Submission time Handle Problem Language Result Execution time Memory
600557 2022-07-21T04:54:29 Z 이동현(#8470) JOI15_building3 (JOI15_building3) C++14
100 / 100
111 ms 14796 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n; --n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    int mx = 0;
    deque<vector<int>> deq;
    multiset<int> st;
    for(int i = 0; i < n; ++i){
        if(a[i] > mx + 1){
            if(a[i] == mx + 2){
                deq.push_back({a[i] - 1, i});
                st.insert(a[i] - 1);
            }
            else{
                cout << "0\n";
                return 0;
            }
        }
        mx = max(mx, a[i]);
    }
    int ans = 0;
    mx = 0;
    for(int i = 0; i < n; ++i){
        if((int)deq.size() && deq.front()[1] < i){
            break;
        }
        if(!(int)st.size()){
            ans += mx;
        }
        else if(*st.begin() == *prev(st.end())){
            int val = *st.begin();
            if(val != a[i] && val <= mx + 1){
                ++ans;
            }
        }
        mx = max(mx, a[i]);
    }
    if(!(int)deq.size()) ans += mx + 1;
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 228 KB Output is correct
21 Correct 87 ms 12104 KB Output is correct
22 Correct 69 ms 11980 KB Output is correct
23 Correct 62 ms 11976 KB Output is correct
24 Correct 87 ms 14796 KB Output is correct
25 Correct 98 ms 14796 KB Output is correct
26 Correct 88 ms 14788 KB Output is correct
27 Correct 82 ms 14788 KB Output is correct
28 Correct 81 ms 14796 KB Output is correct
29 Correct 49 ms 10048 KB Output is correct
30 Correct 62 ms 11592 KB Output is correct
31 Correct 82 ms 12360 KB Output is correct
32 Correct 72 ms 12352 KB Output is correct
33 Correct 64 ms 12488 KB Output is correct
34 Correct 77 ms 12352 KB Output is correct
35 Correct 111 ms 14788 KB Output is correct