結果
問題 | No.154 市バス |
ユーザー |
![]() |
提出日時 | 2016-06-30 16:45:27 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 28 ms / 2,000 ms |
コード長 | 666 bytes |
コンパイル時間 | 1,166 ms |
コンパイル使用メモリ | 158,876 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-13 08:37:03 |
合計ジャッジ時間 | 1,872 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REP(i,a) FOR(i,0,a) int N; string S; int main(){ cin>>N; REP(i,N){ cin>>S; int w=0; bool f=false,p=false; REP(j,S.length()){ if (S[j]=='W'){ w++; f=true; }else if (S[j]=='G'){ w--; f=false; if (w<0){ p=true; } } } if (p || f){ cout<<"impossible"<<endl; continue; } int g=0; REP(j,S.length()){ if (S[j]=='G'){ g++; }else if (S[j]=='R'){ g--; if (g<0){ p=true; } } } if (g || p){ cout<<"impossible"<<endl; continue; } cout<<"possible"<<endl; } return 0; }