結果

問題 No.1734 Decreasing Elements
ユーザー りあんりあん
提出日時 2021-11-05 22:13:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 710 ms / 3,000 ms
コード長 1,137 bytes
コンパイル時間 2,672 ms
コンパイル使用メモリ 214,548 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2024-04-24 06:01:12
合計ジャッジ時間 8,593 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 35 ms
6,940 KB
testcase_08 AC 31 ms
6,888 KB
testcase_09 AC 22 ms
6,764 KB
testcase_10 AC 30 ms
6,844 KB
testcase_11 AC 58 ms
7,016 KB
testcase_12 AC 26 ms
5,388 KB
testcase_13 AC 50 ms
6,916 KB
testcase_14 AC 152 ms
7,584 KB
testcase_15 AC 91 ms
7,324 KB
testcase_16 AC 173 ms
7,540 KB
testcase_17 AC 182 ms
7,484 KB
testcase_18 AC 187 ms
7,648 KB
testcase_19 AC 702 ms
5,376 KB
testcase_20 AC 710 ms
5,376 KB
testcase_21 AC 620 ms
7,780 KB
testcase_22 AC 622 ms
7,972 KB
testcase_23 AC 350 ms
5,376 KB
testcase_24 AC 180 ms
5,376 KB
testcase_25 AC 406 ms
5,996 KB
testcase_26 AC 197 ms
5,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;

const int M = 998244353;
const long long LM = 1LL << 60;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n;
    // n = 200000;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        // a[i] = i + 1;
        cin >> a[i];
    }
    vector<vector<int>> vv;
    int SQ = 500;

    vector<int> v = { 0, 200010 };
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (auto& x : vv) {
            a[i] -= *prev(upper_bound(x.begin(), x.end(), a[i]));
        }
        a[i] -= *prev(upper_bound(v.begin(), v.end(), a[i]));
        if (a[i] > 0) {
            ++ans;
            vector<int> nex;
            for (int j = 0; j < (int)v.size(); ++j) {
                nex.push_back(v[j]);
                if (j + 1 < (int)v.size() && v[j] + a[i] < v[j + 1]) {
                    nex.push_back(v[j] + a[i]);
                }
            }
            v = nex;
        }
        if ((i + 1) % SQ == 0) {
            vv.push_back(v);
            v = { 0, 200010 };
        }
    }
    cout << ans << '\n';
    return 0;
}

0