結果

問題 No.1148 土偶Ⅲ
ユーザー eQeeQe
提出日時 2020-08-20 22:01:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 893 bytes
コンパイル時間 1,823 ms
コンパイル使用メモリ 164,576 KB
実行使用メモリ 9,472 KB
最終ジャッジ日時 2024-04-21 19:20:10
合計ジャッジ時間 4,419 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 32 ms
5,888 KB
testcase_06 AC 102 ms
9,472 KB
testcase_07 AC 55 ms
7,680 KB
testcase_08 AC 82 ms
8,704 KB
testcase_09 AC 82 ms
8,576 KB
testcase_10 AC 35 ms
6,272 KB
testcase_11 AC 66 ms
8,576 KB
testcase_12 AC 6 ms
5,376 KB
testcase_13 AC 11 ms
5,376 KB
testcase_14 AC 9 ms
5,376 KB
testcase_15 AC 44 ms
7,296 KB
testcase_16 AC 18 ms
5,504 KB
testcase_17 AC 100 ms
9,216 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 37 ms
6,272 KB
testcase_20 AC 39 ms
6,912 KB
testcase_21 AC 28 ms
6,272 KB
testcase_22 AC 7 ms
5,376 KB
testcase_23 AC 8 ms
5,376 KB
testcase_24 AC 10 ms
5,376 KB
testcase_25 AC 11 ms
5,376 KB
testcase_26 AC 33 ms
5,376 KB
testcase_27 AC 7 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
template<class T>bool chmax(T &a, const T &b) {if(a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a) {a=b; return 1;} return 0;}
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=998244353;

//for(i=0; i<N; i++) cin >> a[i];



int main(void) {
  ll i, j, k;
  
  ll N, W;
  cin >> N >> W;
  ll a[MAX];
  
  
  
  for(i=0; i<N; i++) cin >> a[i];
  
  map<ll, ll> use;
  ll r=0;
  ll ans=0;
  ll S=0;
  for(ll l=0; l<N; l++) {
    
    while(r<N && !use[a[r]] && S+a[r]<=W) {
      S+=a[r];
      use[a[r]]=1;
      r++;
    }
    chmax(ans, r-l);
    
    if(l==r) r++;
    else {
      S-=a[l];
      use[a[l]]=0;
    }
    
  }
  
  pt(ans);
  
  
  
  
  
}
 
 


0