結果

問題 No.1148 土偶Ⅲ
ユーザー 👑 kmjpkmjp
提出日時 2020-08-06 01:23:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,203 bytes
コンパイル時間 2,600 ms
コンパイル使用メモリ 216,084 KB
実行使用メモリ 16,668 KB
最終ジャッジ日時 2023-10-19 00:42:57
合計ジャッジ時間 5,752 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
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 AC 13 ms
4,600 KB
testcase_24 AC 19 ms
5,084 KB
testcase_25 AC 21 ms
5,244 KB
testcase_26 AC 82 ms
9,612 KB
testcase_27 AC 11 ms
4,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N;
ll W;
ll A[101010];
ll S[101010];
map<int,set<int>> M;
set<int> NG;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>W;
	FOR(i,N) {
		cin>>A[i];
		M[A[i]].insert(i);
		if(M[A[i]].size()==2) NG.insert(i);
		S[i+1]=S[i]+A[i];
	}
	int ma=0;
	FOR(i,N) {
		x=lower_bound(S+i,S+N+1,S[i]+W)-S;
		if(NG.size()) x=min(x,*NG.begin());
		ma=max(ma,x-i);
		
		M[A[i]].erase(i);
		if(M[A[i]].size()) {
			auto it=M[A[i]].begin();
			NG.erase(*it);
			it++;
			if(it!=M[A[i]].end()) NG.insert(*it);
		}
		
	}
	cout<<ma<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0