結果

問題 No.1148 土偶Ⅲ
ユーザー iiljj
提出日時 2021-01-14 00:20:41
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,505 bytes
コンパイル時間 2,428 ms
コンパイル使用メモリ 69,144 KB
最終ジャッジ日時 2025-01-17 17:39:19
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#include <stdio.h>
#include <sys/mman.h>
#include <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::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