結果
| 問題 |
No.2042 RGB Caps
|
| コンテスト | |
| ユーザー |
merlin
|
| 提出日時 | 2022-08-19 21:49:52 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 283 ms / 2,000 ms |
| コード長 | 1,503 bytes |
| コンパイル時間 | 2,714 ms |
| コンパイル使用メモリ | 78,300 KB |
| 実行使用メモリ | 57,760 KB |
| 最終ジャッジ日時 | 2024-11-16 01:55:28 |
| 合計ジャッジ時間 | 6,125 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 16 |
ソースコード
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));
}
}
merlin