답안 #703356

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
703356 2023-02-27T07:07:27 Z niter Sandcastle 2 (JOI22_ho_t5) C++14
0 / 100
1 ms 468 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...);
}

bool cmp_ff(pii XXX, pii YYY){
    return (XXX.ff != YYY.ff) ? (XXX.ff < YYY.ff) : (XXX.ss < YYY.ss);
}
bool cmp_ss(pii XXX, pii YYY){
    return (XXX.ss != YYY.ss) ? (XXX.ss < YYY.ss) : (XXX.ff < YYY.ff);
}

int main(){
    int h, w;
    cin >> h >> w;
    int a[h+10];
    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();
            }
            else break;
        }
        S1.push(a[i]);
        ans += S1.size() - 1;

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

    return 0;
}
/*
1 5
2 4 7 1 5
*/

Compilation message

Main.cpp: In function 'std::ostream& operator<<(std::ostream&, std::pair<int, int>)':
Main.cpp:13:1: warning: no return statement in function returning non-void [-Wreturn-type]
   13 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -