結果

問題 No.1148 土偶Ⅲ
ユーザー trineutrontrineutron
提出日時 2020-08-06 04:17:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 742 bytes
コンパイル時間 5,303 ms
コンパイル使用メモリ 210,416 KB
実行使用メモリ 4,888 KB
最終ジャッジ日時 2023-10-19 05:30:09
合計ジャッジ時間 4,232 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 15 ms
4,348 KB
testcase_06 AC 41 ms
4,624 KB
testcase_07 AC 27 ms
4,348 KB
testcase_08 AC 36 ms
4,360 KB
testcase_09 AC 36 ms
4,360 KB
testcase_10 AC 17 ms
4,348 KB
testcase_11 AC 34 ms
4,360 KB
testcase_12 AC 4 ms
4,348 KB
testcase_13 AC 6 ms
4,348 KB
testcase_14 AC 5 ms
4,348 KB
testcase_15 AC 24 ms
4,348 KB
testcase_16 AC 11 ms
4,348 KB
testcase_17 AC 41 ms
4,624 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 18 ms
4,348 KB
testcase_20 AC 21 ms
4,348 KB
testcase_21 AC 16 ms
4,348 KB
testcase_22 AC 4 ms
4,348 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, w;
    cin >> n >> w;
    vector<int64_t> a(n), s(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
        s.at(i + 1) = s.at(i) + a.at(i);
    }
    int discard = 0, ans = 0;
    set<int64_t> t;
    for (int i = 0; i < n; i++) {
        if (t.find(a.at(i)) == t.end()) {
            t.insert(a.at(i));
            while (s.at(i + 1) - s.at(discard) > w) {
                t.erase(a.at(discard));
                discard++;
            }
            ans = max(ans, i + 1 - discard);
        } else {
            while (a.at(discard) != a.at(i)) {
                discard++;
            }
            discard++;
        }
    }
    cout << ans << endl;
}
0