結果
問題 | No.154 市バス |
ユーザー |
![]() |
提出日時 | 2015-03-04 18:49:47 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 685 ms / 2,000 ms |
コード長 | 1,336 bytes |
コンパイル時間 | 420 ms |
コンパイル使用メモリ | 56,268 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-13 07:10:21 |
合計ジャッジ時間 | 2,978 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 |
コンパイルメッセージ
main.cpp: In function ‘int max(char)’: main.cpp:28:1: warning: control reaches end of non-void function [-Wreturn-type] 28 | } | ^
ソースコード
#include <iostream> std::string S; bool used[1000]; int L; int count(char c){ int res = 0; for(int i=0;i<L;i++){ if(S[i] == c){res++;} } return res; } int find(char c, int ub){ for(int i=0;i<ub;i++){ if(S[i] == c && !used[i]){ return i; } } return -1; } int max(char c){ for(int i=L-1;i>=0;i--){ if(S[i] == c){return i;} } } int main(){ int T; std::cin >> T; while(T--){ std::cin >> S; L = S.size(); for(int i=0;i<L;i++){used[i] = false;} bool can = true; if(count('R') != count('G') || L < count('R') * 3){ can = false; }else{ for(int i=0;i<L;i++){ if(S[i] == 'R'){ int g_index = find('G', i); if(g_index == -1){can = false; break;} used[g_index] = true; int w_index = find('W', g_index); if(w_index == -1){can = false; break;} used[w_index] = true; } } int g_mx = max('G'); for(int i=g_mx+1;i<L;i++){ if(S[i] == 'W'){can = false; break;} } } std::cout << (can ? "possible" : "impossible") << std::endl; } }