結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー crazybbb3crazybbb3
提出日時 2017-01-16 23:08:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 94 ms / 1,000 ms
コード長 2,375 bytes
コンパイル時間 3,573 ms
コンパイル使用メモリ 77,352 KB
実行使用メモリ 54,720 KB
最終ジャッジ日時 2023-08-25 23:53:08
合計ジャッジ時間 8,523 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
50,660 KB
testcase_01 AC 88 ms
52,472 KB
testcase_02 AC 86 ms
52,712 KB
testcase_03 AC 86 ms
52,680 KB
testcase_04 AC 85 ms
52,892 KB
testcase_05 AC 87 ms
52,676 KB
testcase_06 AC 86 ms
52,732 KB
testcase_07 AC 86 ms
52,704 KB
testcase_08 AC 90 ms
52,712 KB
testcase_09 AC 84 ms
53,008 KB
testcase_10 AC 84 ms
53,436 KB
testcase_11 AC 88 ms
52,712 KB
testcase_12 AC 83 ms
52,964 KB
testcase_13 AC 84 ms
52,568 KB
testcase_14 AC 83 ms
52,664 KB
testcase_15 AC 84 ms
53,000 KB
testcase_16 AC 88 ms
53,028 KB
testcase_17 AC 85 ms
52,552 KB
testcase_18 AC 83 ms
54,720 KB
testcase_19 AC 83 ms
52,548 KB
testcase_20 AC 86 ms
52,692 KB
testcase_21 AC 85 ms
52,664 KB
testcase_22 AC 89 ms
52,728 KB
testcase_23 AC 88 ms
53,808 KB
testcase_24 AC 84 ms
52,660 KB
testcase_25 AC 86 ms
53,884 KB
testcase_26 AC 94 ms
52,716 KB
testcase_27 AC 85 ms
52,676 KB
testcase_28 AC 83 ms
52,860 KB
testcase_29 AC 85 ms
52,652 KB
testcase_30 AC 85 ms
52,696 KB
testcase_31 AC 85 ms
52,676 KB
testcase_32 AC 85 ms
52,828 KB
testcase_33 AC 85 ms
53,020 KB
testcase_34 AC 91 ms
52,568 KB
testcase_35 AC 84 ms
52,608 KB
testcase_36 AC 88 ms
53,316 KB
testcase_37 AC 87 ms
52,444 KB
testcase_38 AC 88 ms
52,648 KB
testcase_39 AC 89 ms
52,704 KB
testcase_40 AC 85 ms
53,692 KB
testcase_41 AC 85 ms
52,608 KB
testcase_42 AC 87 ms
52,728 KB
testcase_43 AC 86 ms
53,404 KB
testcase_44 AC 83 ms
52,660 KB
testcase_45 AC 85 ms
52,840 KB
testcase_46 AC 83 ms
52,532 KB
testcase_47 AC 84 ms
53,180 KB
testcase_48 AC 89 ms
52,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    void solve() throws IOException {
        int n = ni();
        String t = "xxxxxxxxxxxxxx";
        String s = t + ns() + ns() + t;
        ArrayList<Integer> list = new ArrayList<>();
        int cnt = 1;
        for (int i = 0; i < s.length() - 1; i++) {
            if (s.charAt(i) == s.charAt(i + 1)) {
                cnt++;
            } else {
                list.add(cnt);
                cnt = 1;
            }
        }
        list.add(cnt);

        int ans = n;
        for (int i = 1; i < list.size(); i += 2) {
            if (list.get(i - 1) >= n || list.get(i + 1) >= n) {
                ans = Math.max(ans, list.get(i) + n);
            }
            if (i != 1 && list.get(i - 1) <= n) {
                ans = Math.max(ans, list.get(i - 2) + list.get(i - 1) + list.get(i));
            }
        }

        out.println(ans);
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}
0