結果

問題 No.1148 土偶Ⅲ
ユーザー face4face4
提出日時 2020-08-05 19:56:10
言語 Java21
(openjdk 21)
結果
AC  
実行時間 228 ms / 2,000 ms
コード長 1,024 bytes
コンパイル時間 2,190 ms
コンパイル使用メモリ 77,672 KB
実行使用メモリ 60,904 KB
最終ジャッジ日時 2023-10-17 11:59:43
合計ジャッジ時間 7,338 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
53,508 KB
testcase_01 AC 54 ms
53,440 KB
testcase_02 AC 53 ms
53,504 KB
testcase_03 AC 54 ms
52,464 KB
testcase_04 AC 54 ms
53,500 KB
testcase_05 AC 155 ms
58,448 KB
testcase_06 AC 228 ms
58,672 KB
testcase_07 AC 197 ms
58,636 KB
testcase_08 AC 203 ms
58,804 KB
testcase_09 AC 219 ms
58,788 KB
testcase_10 AC 161 ms
58,604 KB
testcase_11 AC 227 ms
56,608 KB
testcase_12 AC 116 ms
55,796 KB
testcase_13 AC 120 ms
55,896 KB
testcase_14 AC 117 ms
56,000 KB
testcase_15 AC 188 ms
60,904 KB
testcase_16 AC 148 ms
58,336 KB
testcase_17 AC 209 ms
58,404 KB
testcase_18 AC 86 ms
55,264 KB
testcase_19 AC 163 ms
58,008 KB
testcase_20 AC 174 ms
56,452 KB
testcase_21 AC 174 ms
58,796 KB
testcase_22 AC 115 ms
55,784 KB
testcase_23 AC 112 ms
55,888 KB
testcase_24 AC 136 ms
58,068 KB
testcase_25 AC 136 ms
58,000 KB
testcase_26 AC 180 ms
57,908 KB
testcase_27 AC 119 ms
55,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.HashSet;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");
        int n = Integer.parseInt(line[0]);
        int w = Integer.parseInt(line[1]);
        int a[] = new int[n];
        for(int i = 0; i < n; i++)  a[i] = Integer.parseInt(br.readLine());
        int l = 0, r = 0, sum = 0, ans = 0;
        HashSet<Integer> s = new HashSet<Integer>();
        while(r < n){
            if(sum+a[r] > w){
                sum -= a[l];
                s.remove(a[l++]);
                continue;
            }
            if(s.contains(a[r])){
                while(s.contains(a[r])){
                    sum -= a[l];
                    s.remove(a[l++]);
                }
            }
            sum += a[r];
            s.add(a[r++]);
            ans = Math.max(ans, r-l);
        }
        System.out.println(ans);
    }
}
0