結果

問題 No.2042 RGB Caps
ユーザー merlin
提出日時 2022-08-19 21:36:31
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,181 bytes
コンパイル時間 3,527 ms
コンパイル使用メモリ 77,268 KB
実行使用メモリ 59,524 KB
最終ジャッジ日時 2024-10-08 07:48:25
合計ジャッジ時間 5,660 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 3 WA * 13
権限があれば一括ダウンロードができます

ソースコード

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