結果

問題 No.1148 土偶Ⅲ
ユーザー furafura
提出日時 2020-08-06 04:29:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 478 bytes
コンパイル時間 2,191 ms
コンパイル使用メモリ 210,844 KB
実行使用メモリ 7,724 KB
最終ジャッジ日時 2023-10-19 05:55:31
合計ジャッジ時間 3,893 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 23 ms
5,136 KB
testcase_06 AC 78 ms
7,724 KB
testcase_07 AC 48 ms
6,420 KB
testcase_08 AC 66 ms
7,256 KB
testcase_09 AC 65 ms
7,176 KB
testcase_10 AC 25 ms
5,276 KB
testcase_11 AC 64 ms
7,184 KB
testcase_12 AC 4 ms
4,348 KB
testcase_13 AC 7 ms
4,348 KB
testcase_14 AC 6 ms
4,348 KB
testcase_15 AC 41 ms
6,176 KB
testcase_16 AC 15 ms
4,724 KB
testcase_17 AC 74 ms
7,568 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 26 ms
5,352 KB
testcase_20 AC 37 ms
5,816 KB
testcase_21 AC 26 ms
5,292 KB
testcase_22 AC 5 ms
4,348 KB
testcase_23 AC 6 ms
4,348 KB
testcase_24 AC 7 ms
4,348 KB
testcase_25 AC 8 ms
4,348 KB
testcase_26 AC 25 ms
4,348 KB
testcase_27 AC 5 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int n,w; scanf("%d%d",&n,&w);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);
	a.emplace_back(w+1);

	int ans=0,sum=0,dup=0;
	map<int,int> f;
	for(int l=0,r=-1;l<n;){
		while(sum<=w && dup==0){
			r++;
			sum+=a[r];
			++f[a[r]];
			if(f[a[r]]==2) dup++;
		}

		ans=max(ans,r-l);

		sum-=a[l];
		--f[a[l]];
		if(f[a[l]]==1) dup--;
		l++;
	}
	printf("%d\n",ans);

	return 0;
}
0