結果

問題 No.1328 alligachi-problem
ユーザー norikamenorikame
提出日時 2021-01-08 23:36:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,589 bytes
コンパイル時間 2,470 ms
コンパイル使用メモリ 213,356 KB
実行使用メモリ 25,872 KB
最終ジャッジ日時 2024-04-28 05:53:36
合計ジャッジ時間 13,124 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 148 ms
20,620 KB
testcase_10 AC 112 ms
8,144 KB
testcase_11 AC 148 ms
20,748 KB
testcase_12 AC 148 ms
20,616 KB
testcase_13 AC 148 ms
20,624 KB
testcase_14 AC 148 ms
20,684 KB
testcase_15 AC 113 ms
8,004 KB
testcase_16 AC 148 ms
20,620 KB
testcase_17 AC 147 ms
20,616 KB
testcase_18 AC 150 ms
20,684 KB
testcase_19 AC 149 ms
20,620 KB
testcase_20 AC 149 ms
20,620 KB
testcase_21 AC 149 ms
20,624 KB
testcase_22 AC 149 ms
20,752 KB
testcase_23 AC 114 ms
8,204 KB
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
#define v(t) vector<t>
#define p(t) pair<t, t>
#define p2(t, s) pair<t, s>
#define vp(t) v(p(t))

#define rep(i, n) for (int i=0,i##_len=((int)(n)); i<i##_len; ++i)
#define rep2(i, a, n) for (int i=((int)(a)),i##_len=((int)(n)); i<=i##_len; ++i)
#define repr(i, n) for (int i=((int)(n)-1); i>=0; --i)
#define rep2r(i, a, n) for (int i=((int)(n)),i##_len=((int)(a)); i>=i##_len; --i)

#define repi(itr, c) for (__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); ++itr)
#define repir(itr, c) for (__typeof((c).rbegin()) itr=(c).rbegin(); itr!=(c).rend(); ++itr)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define eb emplace_back

#define INF (1e9)
#define LINF (1e18)
#define PI (acos(-1))
#define EPS (1e-7)
#define DEPS (1e-10)

// 解説読んで提出したい(やりかけ)

int n, rnum, bnum;
v(int) ans, cnt;
v(v(int)) rb;
v(p(p(int))) xy;
bool dfs(int r, int b) {
    if (r+b == n) return true;
    if (r < rnum) {
        int rid = rb[0][r];
        if (cnt[0] == xy[rid].first.first) {
            ans[r+b] = xy[rid].second.second + 1;
            cnt[xy[rid].first.second]++;
            if (dfs(r+1, b)) return true;
            cnt[xy[rid].first.second]--;
            ans[r+b] = 0;
        }
    }
    if (b < bnum) {
        int bid = rb[1][b];
        if (cnt[1] == xy[bid].first.first) {
            ans[r+b] = xy[bid].second.second + 1;
            cnt[(1+xy[bid].first.second)%2]++;
            if (dfs(r, b+1)) return true;
            cnt[(1+xy[bid].first.second)%2]--;
            ans[r+b] = 0;
        }
    }
    return false;
}

int main(){
    cin >> n;
    xy = v(p(p(int)))(n);
    rep(i, n) {
        char ci, xi;
        cin >> ci >> xi >> xy[i].first.first;
        xy[i].first.second = ((ci==xi)?0:-1);
        xy[i].second.first = ((xi=='R')?0:1);
        xy[i].second.second = i;
    }
    VSORT(xy);
    rep(i, n) xy[i].first.second *= -1;
    rb = v(v(int))(2);
    rep(i, n) rb[xy[i].second.first].pb(i);
    rnum = sz(rb[0]);
    bnum = sz(rb[1]);
    ans = v(int)(n);
    cnt = v(int)(2);
    if (dfs(0, 0)) {
        cout << "Yes" << endl;
        rep(i, n) printf("%d%c", ans[i], (i<n-1?' ':'\n'));
    }
    else cout << "No" << endl;
    return 0;
}
0