結果

問題 No.1328 alligachi-problem
ユーザー 👑 emthrmemthrm
提出日時 2020-12-25 00:29:16
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 2,578 bytes
コンパイル時間 2,395 ms
コンパイル使用メモリ 216,260 KB
実行使用メモリ 21,432 KB
最終ジャッジ日時 2023-10-21 15:58:33
合計ジャッジ時間 8,517 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 110 ms
19,320 KB
testcase_10 AC 76 ms
17,736 KB
testcase_11 AC 112 ms
19,320 KB
testcase_12 AC 110 ms
19,320 KB
testcase_13 AC 109 ms
19,320 KB
testcase_14 AC 113 ms
19,320 KB
testcase_15 AC 81 ms
17,736 KB
testcase_16 AC 111 ms
19,320 KB
testcase_17 AC 109 ms
19,320 KB
testcase_18 AC 109 ms
19,320 KB
testcase_19 AC 109 ms
19,320 KB
testcase_20 AC 108 ms
19,320 KB
testcase_21 AC 111 ms
19,320 KB
testcase_22 AC 109 ms
19,320 KB
testcase_23 AC 78 ms
17,736 KB
testcase_24 AC 99 ms
21,432 KB
testcase_25 AC 98 ms
21,168 KB
testcase_26 AC 80 ms
18,792 KB
testcase_27 AC 82 ms
18,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

int tra(char c) {
  return c == 'R' ? 0 : 1;
}

int main() {
  int n; cin >> n;
  vector ball(2, vector(n + 1, vector<int>{}));
  vector<int> c(n);
  REP(i, n) {
    char ci, x; int y; cin >> ci >> x >> y;
    c[i] = tra(ci);
    ball[tra(x)][y].emplace_back(i);
  }
  REP(j, n) {
    sort(ALL(ball[0][j]), [&](int a, int b) { return c[a] < c[b]; });
    if (ball[0][j].size() >= 2 && ball[0][j][0] == 0 && ball[0][j][0] == ball[0][j][1]) {
      cout << "No\n";
      return 0;
    }
  }
  REP(j, n) {
    sort(ALL(ball[1][j]), [&](int a, int b) { return c[a] > c[b]; });
    if (ball[1][j].size() >= 2 && ball[1][j][0] == 1 && ball[1][j][0] == ball[1][j][1]) {
      cout << "No\n";
      return 0;
    }
  }
  int p[2] = {};
  vector<int> ans;
  while (ans.size() < n) {
    if (ball[0][p[0]].empty() && ball[1][p[1]].empty()) {
      cout << "No\n";
      return 0;
    }
    if (ball[0][p[0]].empty()) {
      int id = ball[1][p[1]].back();
      ball[1][p[1]].pop_back();
      ans.emplace_back(id);
      ++p[c[id]];
    } else if (ball[1][p[1]].empty()) {
      int id = ball[0][p[0]].back();
      ball[0][p[0]].pop_back();
      ans.emplace_back(id);
      ++p[c[id]];
    } else if (c[ball[0][p[0]].back()] == 1 && c[ball[1][p[1]].back()] == 0) {
      cout << "No\n";
      return 0;
    } else if (c[ball[0][p[0]].back()] == 0) {
      int id = ball[0][p[0]].back();
      ball[0][p[0]].pop_back();
      ans.emplace_back(id);
      ++p[c[id]];
    } else {
      int id = ball[1][p[1]].back();
      ball[1][p[1]].pop_back();
      ans.emplace_back(id);
      ++p[c[id]];
    }
  }
  cout << "Yes\n";
  REP(i, n) cout << ans[i] + 1 << " \n"[i + 1 == n];
  return 0;
}
0