結果

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

ソースコード

diff #

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

const int kMAX_N = 100010;

int N;
int a[kMAX_N];

void Solve() {
    reverse(a, a + N);
    int ans = 0, s = 0, num = N;
    while (s < N) {
        int t = s;
        while (t < N && a[t] != num) {
            if (a[t] < num) ans++;
            t++;
        }
        num--;
        s = t + 1;
    }
    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