結果

問題 No.2042 RGB Caps
ユーザー merlinmerlin
提出日時 2022-08-19 21:49:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 275 ms / 2,000 ms
コード長 1,503 bytes
コンパイル時間 1,898 ms
コンパイル使用メモリ 77,968 KB
実行使用メモリ 58,076 KB
最終ジャッジ日時 2024-04-27 20:32:48
合計ジャッジ時間 5,304 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
50,140 KB
testcase_01 AC 49 ms
50,144 KB
testcase_02 AC 50 ms
50,344 KB
testcase_03 AC 49 ms
50,172 KB
testcase_04 AC 49 ms
50,368 KB
testcase_05 AC 49 ms
50,276 KB
testcase_06 AC 78 ms
51,688 KB
testcase_07 AC 176 ms
56,556 KB
testcase_08 AC 217 ms
57,300 KB
testcase_09 AC 152 ms
54,836 KB
testcase_10 AC 252 ms
57,504 KB
testcase_11 AC 128 ms
52,860 KB
testcase_12 AC 275 ms
57,688 KB
testcase_13 AC 268 ms
58,076 KB
testcase_14 AC 270 ms
57,728 KB
testcase_15 AC 52 ms
50,200 KB
testcase_16 AC 161 ms
55,468 KB
testcase_17 AC 127 ms
54,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        String s[]=bu.readLine().split(" ");
        int n=Integer.parseInt(s[0]),k=Integer.parseInt(s[1]);

        int i;
        char ans[]=new char[n],q[]=new char[n];
        Arrays.fill(ans,' '); Arrays.fill(q,' ');
        for(i=0;i<k;i++)
        {
            s=bu.readLine().split(" ");
            int in=Integer.parseInt(s[0])-1;
            q[in]=s[1].charAt(0);
        }

        String ways[]={"RGB","RBG","BRG","BGR","GRB","GBR"};
        for(i=0;i<n;i+=3)
        for(String x:ways)
        {
            int j;
            for(j=0;j<3;j++)
            if(i+j<n) ans[i+j]=x.charAt(j);

            int c[]=new int[3];
            boolean ok=true;
            for(j=0;j<3;j++)
            if(i+j<n)
            {
                if(ans[i+j]=='R') c[0]++;
                else if(ans[i+j]=='B') c[1]++;
                else c[2]++;

                int max=Math.max(Math.max(c[0],c[1]),c[2]);
                if(q[i+j]!=' ')
                {
                    int here=2;
                    if(q[i+j]=='R') here=0;
                    else if(q[i+j]=='B') here=1;
                    if(c[here]!=max) {ok=false; break;}
                }
            }
            if(ok) break;
        }
        System.out.println(new String(ans));
    }
}
0