結果

問題 No.154 市バス
ユーザー pekempeypekempey
提出日時 2018-02-11 18:57:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 583 bytes
コンパイル時間 657 ms
コンパイル使用メモリ 70,008 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-28 17:39:42
合計ジャッジ時間 1,885 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

bool solve(string s) {
  const int n = s.size();
  int W = 0;
  int WW = 0;
  int G = 0;

  for (int i = 0; i < n; i++) {
    if (s[i] == 'W') {
      W++;
      WW++;
    } else if (s[i] == 'G') {
      WW = 0;
      W--;
      G++;
    } else {
      G--;
    }
    if (W < 0 || G < 0) return false;
  }

  return G == 0 && WW == 0;
}

int main() {
  int T;
  cin >> T;
  while (T--) {
    string s;
    cin >> s;

    cout << (solve(s) ? "possible" : "impossible") << endl;
  }
}
0