結果

問題 No.2042 RGB Caps
ユーザー merlinmerlin
提出日時 2022-08-19 21:36:31
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,181 bytes
コンパイル時間 1,859 ms
コンパイル使用メモリ 77,584 KB
実行使用メモリ 60,100 KB
最終ジャッジ日時 2024-04-17 00:16:55
合計ジャッジ時間 5,107 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
50,192 KB
testcase_01 AC 49 ms
50,204 KB
testcase_02 AC 49 ms
50,476 KB
testcase_03 AC 50 ms
50,296 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 79 ms
51,604 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
権限があれば一括ダウンロードができます

ソースコード

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 t[][]=new int[k][2],i;
        for(i=0;i<k;i++)
        {
            s=bu.readLine().split(" ");
            t[i][0]=Integer.parseInt(s[0])-1;
            t[i][1]=s[1].charAt(0);
        }

        String ways[]={"RGB","RBG","BRG","BGR","GRB","GBR"};
        for(String x:ways)
        {
            boolean ok=true;
            for(i=0;i<k;i++)
            {
                int in=t[i][0]%3,max=(t[i][0]/3)+1,cur=max-1;
                for(int j=0;j<3;j++)
                if(t[i][1]==x.charAt(j) && j<=in) cur++;
                if(cur!=max) {ok=false; break;}
            }

            if(ok)
            {
                for(i=0;i<n;i++)
                sb.append(x.charAt(i%3));
                break;
            }
        }
        if(sb.length()==0) sb.append("-1");
        System.out.println(sb);
    }
}
0