結果

問題 No.154 市バス
ユーザー stoqstoq
提出日時 2020-03-26 01:44:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 2,026 bytes
コンパイル時間 1,584 ms
コンパイル使用メモリ 169,188 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 12:03:57
合計ジャッジ時間 2,410 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld DINF = 1e12;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  int q;
  cin >> q;
  map<char, int> mp;
  rep(qi, q)
  {
    string s;
    cin >> s;

    reverse(all(s));
    int r = 0, g = 0;
    bool w = false;
    bool can = true;
    for (auto c : s)
    {
      if (c == 'R')
      {
        r++;
      }
      else if (c == 'G')
      {
        if (r == 0)
        {
          can = false;
          break;
        }
        else
        {
          r--, g++;
        }
      }
      else if (c == 'W')
      {
        if (g > 0)
        {
          g--;
          w = true;
        }
        else if (!w)
        {
          can = false;
          break;
        }
      }
    }

    if (r > 0 || g > 0)
      can = false;
    possible(can);
  }
  return 0;
}
0