답안 #703359

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
703359 2023-02-27T07:10:41 Z niter Sandcastle 2 (JOI22_ho_t5) C++14
9 / 100
20 ms 1028 KB
#include <bits/stdc++.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define STL(i, x) for(auto &i:x) cout << i << " "; cout << "\n";
using namespace std;

/*ostream& operator<<(ostream &os, pii XXX){
    cout << "[" << XXX.ff << ", " << XXX.ss << "]";
}
void db(){
    cout << "\n";
}
template<class T, class ...U>
void db(T XXX, U ...YYY){
    cout << XXX;  db(YYY...);
}*/

int main(){
    int h, w;
    cin >> h >> w;
    int a[50050];
    stack<int> S1, S2;
    long long ans = 0;
    loop(i,0,w){
        cin >> a[i];
        while(true){
            if(S1.empty()) break;
            if(S1.top() > a[i]){
                while(!S1.empty())
                    S1.pop();
                break;
            }
            else break;
        }
        S1.push(a[i]);
        ans += (int)(S1.size()) - 1;

        while(true){
            if(S2.empty()) break;
            if(S2.top() < a[i]){
                while(!S2.empty())
                    S2.pop();
                break;
            }
            else break;
        }
        S2.push(a[i]);
        ans += (int)(S2.size()) - 1;
    }
    cout << ans+w << "\n";

    return 0;
}
/*
1 5
2 4 7 1 5
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 16 ms 1028 KB Output is correct
3 Correct 16 ms 868 KB Output is correct
4 Correct 16 ms 964 KB Output is correct
5 Correct 16 ms 852 KB Output is correct
6 Correct 20 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -