結果

問題 No.154 市バス
ユーザー zakuro9715zakuro9715
提出日時 2016-06-19 23:46:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 938 bytes
コンパイル時間 430 ms
コンパイル使用メモリ 52,760 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-03 11:49:51
合計ジャッジ時間 1,234 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
4,380 KB
testcase_01 AC 24 ms
4,380 KB
testcase_02 AC 24 ms
4,376 KB
testcase_03 AC 23 ms
4,380 KB
testcase_04 AC 24 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 21 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

bool replace_before(char c, char c2, int n)
{
  for(int i = n - 1; i >= 0; i--)
  {
    if (s[i] == c)
    {
      s[i] = '#';
      return true;
    }
  }
  return false;
}

int main()
{
  int T;
  cin >> T;
  for(int t = 0; t < T; t++)
  {
    cin >> s;
    int w = 0, g = 0, r = 0;
    bool ok = true;
    bool extra_w = false;
    for (int i = 0; i < s.length(); i++)
    {
      if (s[i] == 'W')
      {
        w++;
        extra_w = true;
      }
      if (s[i] == 'G')
      {
        g++;
        extra_w = false;
        if (--w < 0)
        {
          ok = false;
          break;
        }
      }
      if (s[i] == 'R')
      {
        r++;
        if (--g < 0)
        {
          ok = false;
          break;
        }
      }
    }
    if (ok && !extra_w && g == 0)
      cout << "possible" << endl;
    else
      cout << "impossible" << endl;
  }
}
0