답안 #475129

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
475129 2021-09-21T08:55:53 Z HossamHero7 Po (COCI21_po) C++14
40 / 70
1000 ms 2252 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define endl '\n'
void solve(){
    int n;
    cin>>n;
    vector <ll> v(n);
    for(auto &i:v) cin>>i;
    vector <ll> tar;
    for(int i=0;i<n;i++) tar.push_back(0);
    int ans = 0;
    while(v != tar){
        int f = -1;
        int e = -1;
        for(int i=0;i<n;i++){
            if(v[i] == 0 && e != -1) break;
            else if(v[i]){
                if(f == -1) f = i;
                e = i;
            }
        }
        ll mn = 1e18;
        for(int i=f;i<=e;i++){
            mn = min(mn,v[i]);
        }
        for(int i=f;i<=e;i++){
            v[i] -= mn;
        }
        ans ++;
    }
    cout<<ans<<endl;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);      cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 924 ms 1360 KB Output is correct
5 Execution timed out 1087 ms 2064 KB Time limit exceeded
6 Execution timed out 1086 ms 2252 KB Time limit exceeded
7 Execution timed out 1092 ms 2252 KB Time limit exceeded