結果

問題 No.154 市バス
ユーザー zakuro9715zakuro9715
提出日時 2016-06-19 23:40:38
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,075 bytes
コンパイル時間 430 ms
コンパイル使用メモリ 55,772 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 09:44:47
合計ジャッジ時間 1,447 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
5,248 KB
testcase_01 AC 35 ms
5,376 KB
testcase_02 AC 35 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 33 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 94 ms
5,376 KB
testcase_08 AC 2 ms
5,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;
    if (s[s.length() - 1] != 'R')
    {
        cout << "impossible" << endl;
        continue;
    }
    bool ok = true;
    bool extra_w = false;
    bool extra_g = false;
    for (int i = 0; i < s.length(); i++)
    {
      if (s[i] == 'W')
        extra_w = true;
      if (s[i] == 'G')
      {
        extra_w = false;
        extra_g = true;
        if (!replace_before('W', 'w', i))
        {
          ok = false;
          break;
        }
      }
      if (s[i] == 'R')
      {
        extra_g = false;
        if (!replace_before('G', 'g', i))
        {
          ok = false;
          break;
        }
      }
    }
    if (ok && !extra_w && !extra_g)
      cout << "possible" << endl;
    else
      cout << "impossible" << endl;
  }
}
0