結果

問題 No.154 市バス
ユーザー itezpaceitezpace
提出日時 2016-07-25 23:51:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 1,045 bytes
コンパイル時間 440 ms
コンパイル使用メモリ 56,544 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 09:54:13
合計ジャッジ時間 1,226 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
5,248 KB
testcase_01 AC 31 ms
5,376 KB
testcase_02 AC 31 ms
5,376 KB
testcase_03 AC 28 ms
5,376 KB
testcase_04 AC 31 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 25 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:37:5: warning: ‘f’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   37 |     if(f==0){
      |     ^~

ソースコード

diff #

#include <iostream>
#include <string>
using namespace std;

int main(){
  int t;
  cin>>t;
  string s;
  for(int i=0; i<t; ++i){
    cin>>s;
    int w,g,r,f;
    w=0;
    g=0;
    r=0;
    for(int j=0; j<s.size(); ++j){
      f=0;
      if(s[j]=='W') w++;
      if(s[j]=='G'){
        if(w>g){
          g++;
        } else {
          f=1;
          cout<<"impossible"<<endl;
          break;
        }
      }
      if(s[j]=='R'){
        if(w>=g && g>r){
          r++;
        } else {
          f=1;
          cout<<"impossible"<<endl;
          break;
        }
      }
    }
    if(f==0){
      int a,b;
      a=0;
      b=0;
      for(int i=s.size()-1; i>=0; --i){
        if(s[i]=='W'){
          if(a<1 || b<1){
            f=1;
            cout<<"impossible"<<endl;
            break;
          }
        }
        if(s[i]=='G') a++;
        if(s[i]=='R') b++;
      }
    }
    if(f==0){
      if(w>=g && w>=r && g==r){
        cout<<"possible"<<endl;
      } else {
        cout<<"impossible"<<endl;
      }
    }
  }
  return 0;
}
0