結果
問題 | No.2148 ひとりUNO |
ユーザー | ei1333333 |
提出日時 | 2022-11-18 22:36:41 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,460 bytes |
コンパイル時間 | 2,608 ms |
コンパイル使用メモリ | 223,264 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-11 23:58:24 |
合計ジャッジ時間 | 24,807 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
6,820 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | AC | 751 ms
6,816 KB |
testcase_38 | AC | 752 ms
6,816 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; } vector< int > parts; for(auto& c : old_parts) { if(c == 1 or c == 2 or c == 4 or c == 8) parts.emplace_back(c); } 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) { return *max_element(cnt.begin(), cnt.end()) == 0; } bool type = __builtin_popcount(parts[idx]) == 1; for (int i = 0; i < cnt.size(); i++) { if (cnt[i] > 0 and (parts[idx] & i) == parts[idx]) { int sub = type ? cnt[i] : 1; cnt[i] -= sub; if (i != parts[idx]) cnt[i ^ parts[idx]] += sub; if (dfs(dfs, idx - 1)) return true; if (i != parts[idx]) cnt[i ^ parts[idx]] -= sub; cnt[i] += sub; } } 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(); } }