結果

問題 No.1328 alligachi-problem
ユーザー trineutrontrineutron
提出日時 2020-12-25 14:24:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,157 bytes
コンパイル時間 2,337 ms
コンパイル使用メモリ 216,132 KB
実行使用メモリ 45,776 KB
最終ジャッジ日時 2023-10-22 06:09:18
合計ジャッジ時間 11,539 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 165 ms
41,172 KB
testcase_10 AC 106 ms
6,376 KB
testcase_11 AC 166 ms
41,176 KB
testcase_12 AC 167 ms
41,168 KB
testcase_13 AC 168 ms
41,176 KB
testcase_14 AC 168 ms
41,176 KB
testcase_15 AC 107 ms
6,508 KB
testcase_16 AC 168 ms
41,176 KB
testcase_17 AC 168 ms
41,176 KB
testcase_18 AC 169 ms
41,176 KB
testcase_19 AC 168 ms
41,176 KB
testcase_20 AC 168 ms
41,176 KB
testcase_21 AC 170 ms
41,172 KB
testcase_22 AC 169 ms
41,172 KB
testcase_23 AC 106 ms
6,376 KB
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

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 (int(ans.size()) == n) return;
    for (int i = 0; i < 4; 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 (ans.empty()) {
        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