結果

問題 No.1328 alligachi-problem
ユーザー trineutrontrineutron
提出日時 2020-12-25 14:36:16
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,904 ms / 2,000 ms
コード長 2,202 bytes
コンパイル時間 2,629 ms
コンパイル使用メモリ 216,208 KB
実行使用メモリ 41,400 KB
最終ジャッジ日時 2023-10-22 06:21:14
合計ジャッジ時間 15,524 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 5 ms
4,348 KB
testcase_05 AC 5 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 6 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 319 ms
41,288 KB
testcase_10 AC 106 ms
6,364 KB
testcase_11 AC 322 ms
41,292 KB
testcase_12 AC 321 ms
41,284 KB
testcase_13 AC 323 ms
41,292 KB
testcase_14 AC 321 ms
41,292 KB
testcase_15 AC 108 ms
6,496 KB
testcase_16 AC 323 ms
41,292 KB
testcase_17 AC 316 ms
41,292 KB
testcase_18 AC 319 ms
41,292 KB
testcase_19 AC 332 ms
41,292 KB
testcase_20 AC 329 ms
41,292 KB
testcase_21 AC 323 ms
41,288 KB
testcase_22 AC 322 ms
41,288 KB
testcase_23 AC 106 ms
6,364 KB
testcase_24 AC 1,904 ms
41,320 KB
testcase_25 AC 1,893 ms
41,400 KB
testcase_26 AC 297 ms
41,320 KB
testcase_27 AC 299 ms
41,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

bool isok(const vector<vector<pair<int, int>>> &q, const vector<int> &idx, int r, int b) {
    for (int i = 0; i < 4; i++) {
        int color = i % 2 == 0 ? r : b;
        if (idx[i] > int(q[i].size())) return false;
        if (idx[i] < int(q[i].size()) and q[i][idx[i]].first < color) return false;
    }
    return true;
};

void dfs(const vector<vector<pair<int, int>>> &q, vector<int> v, vector<int> &ans, int n) {
    if (clock() >= 1800000) return;
    if (int(ans.size()) == n) return;
    for (int i = 3; i >= 0; i--) {
        if (int(q[i].size()) == v[i]) continue;
        int r = v[0] + v[1], b = v[2] + v[3];
        if (i % 2 == 0) {
            if (q[i][v[i]].first != r) continue;
        } else {
            if (q[i][v[i]].first != b) continue;
        }
        v[i]++;
        r = v[0] + v[1];
        b = v[2] + v[3];
        if (isok(q, v, r, b)) {
            ans.push_back(q[i][v[i] - 1].second);
            dfs(q, v, ans, n);
            if (int(ans.size()) == n) return;
            ans.pop_back();
        }
        v[i]--;
    }
}

int main() {
    int n;
    cin >> n;
    vector<char> c(n), x(n);
    vector<int> y(n);
    for (int i = 0; i < n; i++) {
        cin >> c.at(i) >> x.at(i) >> y.at(i);
    }
    vector<vector<pair<int, int>>> q(4);
    for (int i = 0; i < n; i++) {
        if (c.at(i) == 'R') {
            if (x.at(i) == 'R') {
                q.at(0).emplace_back(y.at(i), i);
            } else {
                q.at(1).emplace_back(y.at(i), i);
            }
        } else {
            if (x.at(i) == 'R') {
                q.at(2).emplace_back(y.at(i), i);
            } else {
                q.at(3).emplace_back(y.at(i), i);
            }
        }
    }
    for (int i = 0; i < 4; i++) {
        sort(q.at(i).begin(), q.at(i).end());
    }
    vector<int> ans;
    dfs(q, vector<int>{0, 0, 0, 0}, ans, n);
    if (int(ans.size()) < n) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    for (int i = 0; i < n; i++) {
        cout << ans.at(i) + 1;
        if (i == n - 1) {
            cout << endl;
        } else {
            cout << " ";
        }
    }
}
0