답안 #475186

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
475186 2021-09-21T11:36:30 Z Ahmed57 Po (COCI21_po) C++14
70 / 70
13 ms 1224 KB
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int n;cin>>n;long long arr[n+1]={0};
    for(int i=1;i<=n;i++)cin>>arr[i];stack<int>s;
    s.push(0);
    long long ans = 0;
    for(int i=1;i<=n;i++){
        while(s.top()>arr[i]){
            s.pop();ans++;
        }
        if(s.top()<arr[i])s.push(arr[i]);
    }
    ans+=s.size()-1;
    cout<<ans<<"\n";
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:6:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    6 |     for(int i=1;i<=n;i++)cin>>arr[i];stack<int>s;
      |     ^~~
Main.cpp:6:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
    6 |     for(int i=1;i<=n;i++)cin>>arr[i];stack<int>s;
      |                                      ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 5 ms 588 KB Output is correct
5 Correct 7 ms 844 KB Output is correct
6 Correct 13 ms 1224 KB Output is correct
7 Correct 13 ms 1096 KB Output is correct