結果
問題 |
No.3171 Color Restoration
|
ユーザー |
![]() |
提出日時 | 2025-06-06 21:30:21 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 5,803 bytes |
コンパイル時間 | 4,109 ms |
コンパイル使用メモリ | 301,760 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-06-06 21:30:26 |
合計ジャッジ時間 | 4,981 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
#include <bits/stdc++.h> #include <cassert> using namespace std; using ll = long long int; using u64 = unsigned long long; using pll = pair<ll, ll>; // #include <atcoder/all> // using namespace atcoder; #define REP(i, a, b) for (ll i = (a); i < (b); i++) #define REPrev(i, a, b) for (ll i = (a); i >= (b); i--) #define ALL(coll) (coll).begin(), (coll).end() #define SIZE(v) ((ll)((v).size())) #define REPOUT(i, a, b, exp, sep) REP(i, (a), (b)) cout << (exp) << (i + 1 == (b) ? "" : (sep)); cout << "\n" // @@ !! LIM(perm) // ---- inserted library file perm.cc template <bool dup> struct IntPermBase { int n; int r; vector<int> vec; bool started; bool start_check() { if constexpr (dup) { if (not ((1 <= n and 0 <= r) or (n == 0 and r == 0))) return false; } else { if (not (0 <= n and 0 <= r and r <= n)) return false; } started = true; vec.resize(r, 0); return true; } bool finish() { vec.resize(0); started = false; return false; } IntPermBase(int n_, int r_) : n(n_), r(r_), started(false) {} int at(int i) const { return vec[i]; } const vector<int>& vec_view() const { return vec; } }; struct IntPerm : IntPermBase<false> { vector<vector<int>> cands; vector<int> cidx; bool start_check() { if (not IntPermBase<false>::start_check()) return false; iota(vec.begin(), vec.end(), 0); cands.resize(r); cidx.resize(r); for (int i = 0; i < r; i++) { for (int j = n - 1; j >= i; j--) cands[i].push_back(j); cidx[i] = n - i - 1; } return true; } bool finish() { cands.resize(0); cidx.resize(0); return IntPermBase<false>::finish(); } IntPerm(int n_, int r_) : IntPermBase<false>(n_, r_) {} bool get() { if (not started) return start_check(); int i = r - 1; for (; i >= 0 and cidx[i] == 0; i--); if (i < 0) return finish(); vec[i] = cands[i][--cidx[i]]; for (int j = i + 1; j < r; j++) { if (j == i + 1) { cands[j].resize(0); for (int k = 0; k < (int)cands[i].size(); k++) { if (k == cidx[i]) continue; cands[j].push_back(cands[i][k]); } }else { cands[j] = cands[j - 1]; cands[j].pop_back(); } cidx[j] = n - j - 1; vec[j] = cands[j][cidx[j]]; } return true; } }; struct IntComb : IntPermBase<false> { bool start_check() { if (not IntPermBase<false>::start_check()) return false; iota(vec.begin(), vec.end(), 0); return true; } IntComb(int n_, int r_) : IntPermBase<false>(n_, r_) {} bool get() { if (not started) return start_check(); int i = r - 1; for (; i >= 0 and vec[i] == n - r + i; i--); if (i < 0) return finish(); vec[i]++; for (int j = i + 1; j < r; j++) vec[j] = vec[j - 1] + 1; return true; } }; struct IntDupPerm : IntPermBase<true> { IntDupPerm(int n_, int r_) : IntPermBase<true>(n_, r_) {} bool get() { if (not started) return start_check(); for (int i = r - 1; i >= 0; vec[i--] = 0) if (++vec[i] < n) return true; return finish(); } }; struct IntDupComb : IntPermBase<true> { IntDupComb(int n_, int r_) : IntPermBase<true>(n_, r_) {} bool get() { if (not started) return start_check(); int i = r - 1; for (; i >= 0 and vec[i] == n - 1; i--); if (i < 0) return finish(); vec[i]++; for (int j = i + 1; j < r; j++) vec[j] = vec[i]; return true; } }; template<typename INT> struct IntDirProd { vector<INT> lim; int r; vector<INT> vec; bool started; IntDirProd(const vector<INT>& lim_) : lim(lim_), r(lim.size()), started(false) {} int at(int i) const { return vec[i]; } const vector<INT>& vec_view() const { return vec; } bool start_check() { for (int i = 0; i < r; i++) if (lim[i] == 0) return false; started = true; vec.resize(r, 0); return true; } bool finish() { vec.resize(0); started = false; return false; } bool get() { if (not started) return start_check(); for (int i = r - 1; i >= 0; vec[i--] = 0) if (++vec[i] < lim[i]) return true; return finish(); } }; template<typename INT> struct IntPartition { INT n; vector<INT> vec; bool started = false; IntPartition(INT n_) : n(n_) {} bool get() { if (not started) { started = true; vec = vector<INT>(n, 1); return true; }else if (ssize(vec) == 1) { started = false; return false; }else { ll b = vec.back(); vec.pop_back(); ll a = vec.back(); vec.pop_back(); ll c = a + b; ll a1 = a + 1; while (c - a1 >= a1) { vec.push_back(a1); c -= a1; } vec.push_back(c); return true; } } INT at(int i) const { return vec[i]; } const vector<INT>& vec_view() const { return vec; } }; // ---- end perm.cc // @@ !! LIM -- end mark -- int main(/* int argc, char *argv[] */) { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << setprecision(20); vector<set<string>> names{ {"gray","brown","green","cyan","blue","yellow","orange","red"}, {"gray","green","blue","yellow","red"}, {"gray","green","cyan","blue","violet","orange","red"} }; // @InpVec(3, S, type=string) [3U9iraoc] auto S = vector(3, string()); for (int i = 0; i < 3; i++) { string v; cin >> v; S[i] = v; } // @End [3U9iraoc] IntPerm ip(3, 3); set<vector<string>> svs; while (ip.get()) { auto f = [&]() -> pair<bool, vector<string>> { vector<string> v(3); REP(i, 0, 3) { if (names[ip.at(i)].contains(S[i])) v[ip.at(i)] = S[i]; else return {false, v}; } return {true, v}; }; auto [b, vec] = f(); if (b) svs.insert(vec); } if (ssize(svs) == 1) { cout << "Yes\n"; }else { cout << "No\n"; } return 0; }