結果

問題 No.1148 土偶Ⅲ
ユーザー iiljjiiljj
提出日時 2021-01-14 00:17:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,525 bytes
コンパイル時間 791 ms
コンパイル使用メモリ 63,600 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-14 20:23:10
合計ジャッジ時間 2,058 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 6 ms
4,380 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 4 ms
4,384 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 8 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 4 ms
4,376 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 13 ms
4,380 KB
testcase_27 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")

#include <stdio.h>
#include <sys/mman.h>
#include <unordered_set>

// clang-format off
#define RD(v) int v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;} //
#define RDULL(v) unsigned long long v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;} //
#define wt_int(var,buf,ptr) while(var){buf[ptr++]=var%10;var/=10;}while(ptr--)putc_unlocked(buf[ptr]+'0',stdout);
// clang-format on

int a[100001];
int main() {
    char *rp = (char *)mmap(0l, 1l << 28, 1, 2, 0, 0ll);
    RD(n) RD(w);
    int *ap = a;
    for (int i = 0; i < n; ++i) {
        RD(t);
        *ap++ = t;
    }
    *ap++ = 1000000000 + 9;

    std::unordered_set<int> st;
    int *left = a;
    int sm = 0;
    int ans = 0;
    for (int *right = a; right < ap; ++right) {
        if (st.count(*right) > 0 || sm + *right > w) {
            if (right - left > ans) ans = right - left;
            if (*right > sm) {
                left = right + 1;
                st.clear();
                sm = 0;
                continue;
            }
            while ((st.count(*right) > 0 || sm + *right > w)) {
                st.erase(*left);
                sm -= *left;
                left++;
            }
            sm += *right;
            st.insert(*right);
        } else {
            st.insert(*right);
            sm += *right;
        }
    }

    if (ans == 0) {
        putc_unlocked('0', stdout);
    } else {
        char buf[9];
        n = 0;
        wt_int(ans, buf, n);
    }

    return 0;
}
0