結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
6,816 KB
testcase_01 AC 38 ms
6,944 KB
testcase_02 AC 38 ms
6,940 KB
testcase_03 WA -
testcase_04 AC 34 ms
6,940 KB
testcase_05 WA -
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 109 ms
6,940 KB
testcase_08 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

bool delete_before(char c, 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;
    for (int i = 0; i < s.length(); i++)
    {
      if (s[i] == 'G')
      {
        if (!delete_before('W', i))
        {
          ok = false;
          break;
        }
      }
      if (s[i] == 'R')
      {
        if (!delete_before('G', i))
        {
          ok = false;
          break;
        }
      }
    }
    if (ok)
      cout << "possible" << endl;
    else
      cout << "impossible" << endl;
  }
}
0