답안 #541333

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
541333 2022-03-23T06:45:29 Z AlperenT Po (COCI21_po) C++17
20 / 70
13 ms 3412 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

int n, arr[N], nxt[N], upd[N], cur, ans;

stack<int> stck;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    cin >> n;

    for(int i = 1; i <= n; i++) cin >> arr[i];

    stck.push(n + 1);

    for(int i = n; i >= 1; i--){
        while(arr[stck.top()] >= arr[i]) stck.pop();

        nxt[i] = stck.top();

        stck.push(i);
    }

    for(int i = 1; i <= n; i++){
        cur += upd[i];

        if(cur == arr[i]) continue;
        else{
            upd[nxt[i]] -= arr[i] - cur;

            ans++;

            cur += arr[i] - cur;
        }
    }

    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Runtime error 1 ms 452 KB Execution killed with signal 11
3 Runtime error 1 ms 468 KB Execution killed with signal 11
4 Runtime error 4 ms 980 KB Execution killed with signal 11
5 Runtime error 6 ms 1232 KB Execution killed with signal 11
6 Correct 12 ms 2360 KB Output is correct
7 Runtime error 13 ms 3412 KB Execution killed with signal 11