結果

問題 No.365 ジェンガソート
ユーザー ふーらくたる
提出日時 2016-07-06 10:51:19
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 750 bytes
コンパイル時間 512 ms
コンパイル使用メモリ 66,892 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-12 20:25:45
合計ジャッジ時間 1,860 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16 WA * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;

const int kMAX_N = 100010;

int N;
int a[kMAX_N];

void Solve() {
    reverse(a, a + N);
    priority_queue<int, vector<int>, greater<int> > que;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (que.empty() || (que.top() > a[i])) {
            que.push(a[i]);
        } else {
            while (!que.empty() && que.top() < a[i]) {
                que.pop();
                ans++;
            }
            que.push(a[i]);
        }
    }
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N;

    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    Solve();

    return 0;
}
0