結果

問題 No.1148 土偶Ⅲ
ユーザー okazakisteveokazakisteve
提出日時 2020-08-05 17:29:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 649 bytes
コンパイル時間 1,538 ms
コンパイル使用メモリ 78,008 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 08:15:12
合計ジャッジ時間 2,991 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 15 ms
4,348 KB
testcase_06 AC 38 ms
4,348 KB
testcase_07 AC 25 ms
4,348 KB
testcase_08 AC 32 ms
4,348 KB
testcase_09 AC 31 ms
4,348 KB
testcase_10 AC 16 ms
4,348 KB
testcase_11 AC 30 ms
4,348 KB
testcase_12 AC 4 ms
4,348 KB
testcase_13 AC 6 ms
4,348 KB
testcase_14 AC 4 ms
4,348 KB
testcase_15 AC 21 ms
4,348 KB
testcase_16 AC 10 ms
4,348 KB
testcase_17 AC 38 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 16 ms
4,348 KB
testcase_20 AC 19 ms
4,348 KB
testcase_21 AC 15 ms
4,348 KB
testcase_22 AC 4 ms
4,348 KB
testcase_23 AC 7 ms
4,348 KB
testcase_24 AC 10 ms
4,348 KB
testcase_25 AC 12 ms
4,348 KB
testcase_26 AC 36 ms
4,348 KB
testcase_27 AC 7 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream> 
#include <vector>
#include <set>
#include <cstdint> 
using namespace std;

int main() {
  long long int n,w;
  cin >> n >> w;
  vector<long long int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  long long int  res = 0, right = 0, sum = 0;
  set<int> member;
  for (int left = 0; left < n; ++left) {
    while (right < n && !member.count(a[right]) && sum + a[right] <= w) {
      member.insert(a[right]);
      sum += a[right];
      ++right;
    }
    res = max(res, right - left);
    if (left == right) ++right;
    else {
      member.erase(a[left]);
      sum -= a[left];
    }
  }
  cout << res << endl;
  return 0;
}
0