結果
問題 |
No.1148 土偶Ⅲ
|
ユーザー |
|
提出日時 | 2020-08-06 04:29:24 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 125 ms / 2,000 ms |
コード長 | 478 bytes |
コンパイル時間 | 2,941 ms |
コンパイル使用メモリ | 200,408 KB |
最終ジャッジ日時 | 2025-01-12 15:15:44 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:8:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 8 | int n,w; scanf("%d%d",&n,&w); | ~~~~~^~~~~~~~~~~~~~ main.cpp:10:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 10 | rep(i,n) scanf("%d",&a[i]); | ~~~~~^~~~~~~~~~~~
ソースコード
#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; }