結果

問題 No.2930 Larger Mex
ユーザー loop0919loop0919
提出日時 2024-09-13 16:31:26
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,380 bytes
コンパイル時間 1,073 ms
コンパイル使用メモリ 97,244 KB
実行使用メモリ 13,640 KB
最終ジャッジ日時 2024-10-12 06:39:35
合計ジャッジ時間 20,910 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,248 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
5,248 KB
testcase_05 WA -
testcase_06 AC 2 ms
5,248 KB
testcase_07 AC 2 ms
5,248 KB
testcase_08 AC 691 ms
6,912 KB
testcase_09 AC 810 ms
6,656 KB
testcase_10 AC 663 ms
7,040 KB
testcase_11 AC 295 ms
6,272 KB
testcase_12 AC 295 ms
7,552 KB
testcase_13 AC 986 ms
7,168 KB
testcase_14 AC 142 ms
7,936 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 28 ms
7,296 KB
testcase_27 AC 24 ms
6,528 KB
testcase_28 AC 27 ms
7,040 KB
testcase_29 AC 27 ms
7,040 KB
testcase_30 AC 32 ms
6,656 KB
testcase_31 AC 27 ms
6,144 KB
testcase_32 AC 33 ms
6,912 KB
testcase_33 AC 34 ms
6,912 KB
testcase_34 WA -
testcase_35 AC 368 ms
5,760 KB
testcase_36 WA -
testcase_37 AC 1,133 ms
7,168 KB
testcase_38 TLE -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// Generated by ChatGPT o1-preview

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

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

    int N, M;
    cin >> N >> M;
    vector<int> A(N + 1);
    for (int i = 1; i <= N; ++i) {
        cin >> A[i];
    }

    vector<int> last_occurrence(M, 0); // 0-based indexing
    vector<int> len(N + 1, 0);
    int l_i = 0;
    for (int i = 1; i <= N; ++i) {
        if (A[i] < M) {
            last_occurrence[A[i]] = i;
        }
        int max_last = 0;
        bool all_present = true;
        for (int j = 0; j < M; ++j) {
            if (last_occurrence[j] == 0) {
                all_present = false;
                break;
            }
            max_last = max(max_last, last_occurrence[j]);
        }
        if (all_present) {
            l_i = max_last;
            len[i] = i - l_i + 1;
        } else {
            len[i] = 0; // Cannot form a valid subarray ending at i
        }
    }

    vector<int> cnt(N + 2, 0); // cnt[k]
    for (int i = 1; i <= N; ++i) {
        if (len[i] > 0) {
            int k = min(len[i], i);
            cnt[k]++;
        }
    }

    vector<long long> ans(N + 2, 0);
    for (int k = N; k >= 1; --k) {
        ans[k] = ans[k + 1] + cnt[k];
    }

    for (int k = 1; k <= N; ++k) {
        cout << ans[k] << "\n";
    }

    return 0;
}
0