結果
問題 | No.2148 ひとりUNO |
ユーザー | ei1333333 |
提出日時 | 2022-12-02 23:33:18 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 695 ms / 2,000 ms |
コード長 | 3,606 bytes |
コンパイル時間 | 2,456 ms |
コンパイル使用メモリ | 222,840 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-11 23:57:59 |
合計ジャッジ時間 | 11,482 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
6,816 KB |
testcase_01 | AC | 91 ms
6,820 KB |
testcase_02 | AC | 93 ms
6,816 KB |
testcase_03 | AC | 90 ms
6,820 KB |
testcase_04 | AC | 101 ms
6,816 KB |
testcase_05 | AC | 87 ms
6,820 KB |
testcase_06 | AC | 89 ms
6,816 KB |
testcase_07 | AC | 88 ms
6,816 KB |
testcase_08 | AC | 90 ms
6,816 KB |
testcase_09 | AC | 101 ms
6,816 KB |
testcase_10 | AC | 89 ms
6,816 KB |
testcase_11 | AC | 82 ms
6,820 KB |
testcase_12 | AC | 89 ms
6,820 KB |
testcase_13 | AC | 98 ms
6,820 KB |
testcase_14 | AC | 88 ms
6,816 KB |
testcase_15 | AC | 98 ms
6,820 KB |
testcase_16 | AC | 49 ms
6,820 KB |
testcase_17 | AC | 43 ms
6,816 KB |
testcase_18 | AC | 46 ms
6,816 KB |
testcase_19 | AC | 46 ms
6,816 KB |
testcase_20 | AC | 46 ms
6,820 KB |
testcase_21 | AC | 44 ms
6,820 KB |
testcase_22 | AC | 48 ms
6,816 KB |
testcase_23 | AC | 46 ms
6,816 KB |
testcase_24 | AC | 46 ms
6,816 KB |
testcase_25 | AC | 44 ms
6,816 KB |
testcase_26 | AC | 406 ms
6,820 KB |
testcase_27 | AC | 391 ms
6,820 KB |
testcase_28 | AC | 392 ms
6,816 KB |
testcase_29 | AC | 399 ms
6,816 KB |
testcase_30 | AC | 378 ms
6,816 KB |
testcase_31 | AC | 382 ms
6,816 KB |
testcase_32 | AC | 393 ms
6,820 KB |
testcase_33 | AC | 379 ms
6,816 KB |
testcase_34 | AC | 395 ms
6,816 KB |
testcase_35 | AC | 390 ms
6,816 KB |
testcase_36 | AC | 695 ms
6,816 KB |
testcase_37 | AC | 693 ms
6,820 KB |
testcase_38 | AC | 693 ms
6,820 KB |
testcase_39 | AC | 3 ms
6,820 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; const string colors = "RGBY"; const string patterns[] = { "A", "AB", "AAB", "ABB", "ABC", "AABB", "AABC", "ABBC", "ABCC", "ABCD", "AABBC", "AABCC", "AABCD", "ABBBC", "ABBCC", "ABBCD", "ABCCD", "ABCDD", "AABBBC", "AABBCC", "AABBCD", "AABCCD", "AABCDD", "ABBBCC", "ABBBCD", "ABBCCD", "ABBCDD", "ABCCBD", "ABCCCD", "ABCCDD", "ABCDDB", "AABBBCC", "AABBBCD", "AABBCCD", "AABBCDD", "AABCCBD", "AABCCCD", "AABCCDD", "AABCDDB", "ABBBCCD", "ABBBCDD", "ABBCCCD", "ABBCCDD", "ABCCBDD", "ABCCCBD", "ABCCCDD", "ABCCDDB", "ABCDDBB", "ABCDDDB", "AABBBCCD", "AABBBCDD", "AABBCCCD", "AABBCCDD", "AABCCBDD", "AABCCCBD", "AABCCCDD", "AABCCDDB", "AABCDDBB", "AABCDDDB", "ABBBCCCD", "ABBBCCDD", "ABBCCCDD", "ABCCBDDB", "ABCCCBDD", "ABCCCDDB", "ABCCDDBB", "ABCCDDDB", "ABCDDBBD", "ABCDDDBB", "AABBBCCCD", "AABBBCCDD", "AABBCCCDD", "AABCCBDDB", "AABCCCBDD", "AABCCCDDB", "AABCCDDBB", "AABCCDDDB", "AABCDDBBD", "AABCDDDBB", "ABBBCCCDD", "ABCCBDDDB", "ABCCCBDDB", "ABCCCDDBB", "ABCCCDDDB", "ABCCDDBBD", "ABCCDDDBB", "AABBBCCCDD", "AABCCBDDDB", "AABCCCBDDB", "AABCCCDDBB", "AABCCCDDDB", "AABCCDDBBD", "AABCCDDDBB", "ABCCCBDDDB", "ABCCCDDBBD", "ABCCCDDDBB", "AABCCCBDDDB", "AABCCCDDBBD", "AABCCCDDDBB", }; void test() { int N; cin >> N; vector< int > C(N), D(N); for (int i = 0; i < N; i++) { char c; cin >> c >> D[i]; C[i] = colors.find(c); } vector< int > perm{0, 1, 2, 3}; do { vector< int > cnt(1 << 4); { map< int, int > mp; for (int i = 0; i < N; i++) { mp[D[i]] |= 1 << perm[C[i]]; } for (auto &p: mp) { cnt[p.second]++; } } for (auto& pattern: patterns) { vector< int > old_parts; for (auto &c: pattern) { int p = (c - 'A'); if (old_parts.empty() or ((old_parts.back() >> p) & 1)) { old_parts.emplace_back(); } old_parts.back() |= 1 << p; } int mask = 0; for(auto& c : old_parts) { if(c == 1 or c == 2 or c == 4 or c == 8) { mask |= c; } } vector< int > parts; for(auto& c : old_parts) { if(c != 1 and c != 2 and c != 4 and c != 8) parts.emplace_back(c); } auto dfs = [&](auto &dfs, int idx) -> bool { if (idx == -1) { for (int i = 0; i < 4; i++) { if ((~mask >> i) & 1) { for (int j = 0; j < cnt.size(); j++) { if((j >> i) & 1 and cnt[j] > 0) { return false; } } } } return true; } for (int i = 0; i < cnt.size(); i++) { if (cnt[i] > 0 and (parts[idx] & i) == parts[idx]) { cnt[i]--; if (i != parts[idx]) cnt[i ^ parts[idx]]++; if (dfs(dfs, idx - 1)) return true; if (i != parts[idx]) cnt[i ^ parts[idx]]--; cnt[i]++; } } return false; }; if (dfs(dfs, (int) parts.size() - 1)) { cout << "YES" << endl; return; } } } while (next_permutation(perm.begin(), perm.end())); cout << "NO" << endl; } int main() { int T; cin >> T; while (T--) { test(); } }