結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー tentententen
提出日時 2020-11-17 21:41:10
言語 Java21
(openjdk 21)
結果
AC  
実行時間 126 ms / 1,000 ms
コード長 1,391 bytes
コンパイル時間 2,415 ms
コンパイル使用メモリ 81,248 KB
実行使用メモリ 56,284 KB
最終ジャッジ日時 2023-09-30 14:28:05
合計ジャッジ時間 10,263 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,824 KB
testcase_01 AC 119 ms
55,776 KB
testcase_02 AC 119 ms
55,568 KB
testcase_03 AC 123 ms
55,800 KB
testcase_04 AC 122 ms
55,748 KB
testcase_05 AC 122 ms
55,536 KB
testcase_06 AC 122 ms
55,536 KB
testcase_07 AC 118 ms
55,880 KB
testcase_08 AC 121 ms
56,044 KB
testcase_09 AC 122 ms
55,904 KB
testcase_10 AC 121 ms
55,800 KB
testcase_11 AC 121 ms
55,756 KB
testcase_12 AC 121 ms
56,076 KB
testcase_13 AC 120 ms
56,176 KB
testcase_14 AC 120 ms
56,156 KB
testcase_15 AC 119 ms
55,700 KB
testcase_16 AC 122 ms
55,708 KB
testcase_17 AC 121 ms
55,772 KB
testcase_18 AC 120 ms
56,076 KB
testcase_19 AC 121 ms
56,036 KB
testcase_20 AC 121 ms
55,532 KB
testcase_21 AC 126 ms
56,156 KB
testcase_22 AC 120 ms
55,900 KB
testcase_23 AC 120 ms
55,940 KB
testcase_24 AC 119 ms
56,140 KB
testcase_25 AC 121 ms
56,024 KB
testcase_26 AC 123 ms
56,212 KB
testcase_27 AC 120 ms
55,552 KB
testcase_28 AC 121 ms
55,876 KB
testcase_29 AC 123 ms
56,244 KB
testcase_30 AC 124 ms
56,000 KB
testcase_31 AC 120 ms
56,060 KB
testcase_32 AC 121 ms
55,788 KB
testcase_33 AC 119 ms
56,004 KB
testcase_34 AC 121 ms
55,564 KB
testcase_35 AC 121 ms
55,532 KB
testcase_36 AC 120 ms
55,960 KB
testcase_37 AC 123 ms
56,164 KB
testcase_38 AC 124 ms
55,824 KB
testcase_39 AC 121 ms
56,060 KB
testcase_40 AC 122 ms
56,104 KB
testcase_41 AC 120 ms
56,284 KB
testcase_42 AC 119 ms
56,092 KB
testcase_43 AC 122 ms
55,684 KB
testcase_44 AC 121 ms
55,804 KB
testcase_45 AC 120 ms
56,260 KB
testcase_46 AC 122 ms
56,176 KB
testcase_47 AC 122 ms
55,604 KB
testcase_48 AC 121 ms
55,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        ArrayList<Integer> cal = new ArrayList<>();
        char prev = 'x';
        int count = 20;
        for (char c : (sc.next() + sc.next()).toCharArray()) {
            if (prev == c) {
                count++;
            } else {
                cal.add(count);
                count = 1;
                prev = c;
            }
        }
        if (prev == 'x') {
            cal.add(count + 20);
        } else {
            cal.add(count);
            cal.add(20);
        }
        if (cal.size() == 1) {
            System.out.println(d);
            return;
        }
        int max = d;
        for (int i = 0; i < cal.size(); i += 2) {
            if (i > 0 && i < cal.size() - 1) {
                if (d >= cal.get(i)) {
                    max = Math.max(max, cal.get(i - 1) + cal.get(i) + cal.get(i + 1));
                } else {
                    max = Math.max(max, cal.get(i - 1) + d);
                    max = Math.max(max, cal.get(i + 1) + d);
                }
            } else if (i == 0) {
                max = Math.max(max, cal.get(1) + d);
            } else {
                max = Math.max(max, cal.get(cal.size() - 2) + d);
            }
        }
        System.out.println(max);
    }
}
0