結果
問題 | No.154 市バス |
ユーザー |
|
提出日時 | 2018-03-24 19:04:39 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 16 ms / 2,000 ms |
コード長 | 1,617 bytes |
コンパイル時間 | 146 ms |
コンパイル使用メモリ | 23,296 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-25 03:14:38 |
合計ジャッジ時間 | 805 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:47:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 47 | scanf("%d",&N); | ~~~~~^~~~~~~~~ main.cpp:50:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 50 | scanf("%s",S); | ~~~~~^~~~~~~~
ソースコード
#include <stdio.h> #include <string.h> //WはG,Rのペアに一つづつ必要 //それ以外のWは最後に出てくるG,Rのペアに所属することにしてもんだいない //最後から見ていったときにRの数>Gの数になっているか? => G,Rの順にペアが作れることが保証される //先頭から見ていったときにWの数>Gの数>Rの数になっているか? => W,G,RとなるWが必ず選べる //最後に出てくるGの後ろにWが入っていないか? => ****GWR, ****GRWのパターンを消す int isPossibleOneLine(char * S){ int len = strlen(S); if(len <= 3) return 0; int count_w = 0, count_g = 0, count_r = 0; int last_g = 0; //char possible = 1; for(int i = len - 1; i >= 0; i--){ if (S[i] == 'R') count_r++; else if(S[i] == 'G'){ count_g++; if(last_g <= i) last_g = i; } else /*S[i] == 'W'*/ count_w++; if(count_r < count_g) return 0; } count_w = 0; count_g = 0; count_r = 0; for(int i = 0; i < len; i++){ if (S[i] == 'R') count_r++; else if(S[i] == 'G') count_g++; else /*S[i] == 'W'*/ { count_w++; if(last_g < i) return 0; } if(count_w < count_g || count_w < count_r) return 0; } if(count_g == count_r) return 1; else return 0; } int main(){ char S[1001]; int N; scanf("%d",&N); while(N--){ scanf("%s",S); if(isPossibleOneLine(S)) puts("possible"); else puts("impossible"); } }