結果
問題 | No.154 市バス |
ユーザー | jp_ste |
提出日時 | 2015-03-18 05:51:25 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,358 bytes |
コンパイル時間 | 2,192 ms |
コンパイル使用メモリ | 77,288 KB |
実行使用メモリ | 54,000 KB |
最終ジャッジ日時 | 2024-04-21 08:23:18 |
合計ジャッジ時間 | 6,552 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 463 ms
47,732 KB |
testcase_01 | AC | 389 ms
46,192 KB |
testcase_02 | AC | 460 ms
47,524 KB |
testcase_03 | AC | 400 ms
47,284 KB |
testcase_04 | AC | 505 ms
48,204 KB |
testcase_05 | WA | - |
testcase_06 | AC | 103 ms
39,968 KB |
testcase_07 | AC | 515 ms
47,720 KB |
testcase_08 | WA | - |
ソースコード
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for(int i=0; i<T; i++) { char[] S = sc.next().toCharArray(); //一番右はR if(S[S.length-1] != 'R') { System.out.println("impossible"); continue; } //RとGの個数は同じ int rNum = getCharCount(S, 'R'); int gNum = getCharCount(S, 'G'); if(rNum>0 && gNum>0 && (rNum==gNum)) { } else { System.out.println("impossible"); continue; } for(int j=0; j<rNum; j++) { int r = getCharIndex(S, S.length, 'R'); int g = getCharIndex(S, r, 'G'); int w = getCharIndex(S, g, 'W'); if(r<0 || g<0 || w<0) { break; } if( (r > g && r > w) && (w < g && w < r) ) { S[r] = S[g] = S[w] = ' '; } else { break; } } rNum = getCharCount(S, 'R'); if(rNum == 0) { System.out.println("possible"); } else { System.out.println("impossible"); } } } static int getCharIndex(char[] list, int edge, char c) { for(int i=edge-1; i>=0; i--) { if(list[i] == c) return i; } return -1; } static int getCharCount(char[] list, char c) { int ret = 0; for(int i=0; i<list.length; i++) { if(list[i] == c) ret++; } return ret; } }