結果

問題 No.154 市バス
ユーザー goodbatongoodbaton
提出日時 2016-06-19 23:24:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 1,025 bytes
コンパイル時間 750 ms
コンパイル使用メモリ 80,500 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 09:44:17
合計ジャッジ時間 1,353 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
5,248 KB
testcase_01 AC 10 ms
5,376 KB
testcase_02 AC 9 ms
5,376 KB
testcase_03 AC 9 ms
5,376 KB
testcase_04 AC 9 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 6 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:62:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   62 |   scanf("%d",&n);
      |   ~~~~~^~~~~~~~~
main.cpp:65:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   65 |     scanf("%s",s);
      |     ~~~~~^~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 10000

bool calc(char *s){
  int R=0,G=0,W=0;
  int l = strlen(s);

  reverse(s,s+l);

  for(int i=0;i<l;i++){
    if(s[i]=='R') R++;
    
    if(s[i]=='G'){
      if(R==0) return false;
      R--;
      G++;
    }

    if(s[i]=='W'){
      if(G>0){
	G--;
	W++;
      }else if(W==0){
	return false;
      }
    }
  }

  if(R==0 && G==0) return true;
  return false;
}

int main(){
  int n;
  char s[SIZE];
  
  scanf("%d",&n);

  for(int i=0;i<n;i++){
    scanf("%s",s);

    puts(calc(s) ? "possible" : "impossible");
  }
  
  return 0;
}
0