結果

問題 No.2036 Max Middle
ユーザー Manuel1024Manuel1024
提出日時 2022-09-05 11:26:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 1,034 bytes
コンパイル時間 815 ms
コンパイル使用メモリ 74,724 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-12 19:48:02
合計ジャッジ時間 2,775 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 44 ms
4,380 KB
testcase_09 AC 73 ms
4,376 KB
testcase_10 AC 76 ms
4,380 KB
testcase_11 AC 64 ms
4,384 KB
testcase_12 AC 55 ms
4,376 KB
testcase_13 AC 78 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 81 ms
4,380 KB
testcase_17 AC 32 ms
4,380 KB
testcase_18 AC 54 ms
4,380 KB
testcase_19 AC 56 ms
4,380 KB
testcase_20 AC 65 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int guchoku(int n, const vector<int> &a){
    vector<bool> b(n-1);
    for(int i = 0; i < n; i++) b[i] = a[i] < a[i+1];
    vector<int> Q;
    for(int i = 0; i < n-2; i++){
        if(b[i] && !b[i+1]) Q.emplace_back(i);
    }
    int ans = 0;
    while(!Q.empty()){
        int c = Q.back(); Q.pop_back();
        ans++;
        b[c] = false;
        b[c+1] = true;
        if(c-1 >= 0 && b[c-1] && !b[c]) Q.emplace_back(c-1);
        if(c+2 < n-1 && b[c+1] && !b[c+2]) Q.emplace_back(c+1);
    }

    return ans;
}

ll solve(int n, const vector<int> &a){
    vector<bool> b(n-1);
    for(int i = 0; i < n; i++) b[i] = a[i] < a[i+1];
    int cnt = 0;
    ll ans = 0;
    for(int i = b.size()-1; i >= 0; i--){
        if(b[i]){
            cnt++;
            ans += b.size()-i-cnt;
        }
    }
    return ans;
}

int main(){
    int n; cin >> n;
    vector<int> a(n);
    for(auto &it: a) cin >> it;

    cout << solve(n, a) << endl;
    return 0;
}
0