結果
問題 |
No.3171 Color Restoration
|
ユーザー |
![]() |
提出日時 | 2025-06-07 15:39:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,717 bytes |
コンパイル時間 | 1,018 ms |
コンパイル使用メモリ | 82,716 KB |
実行使用メモリ | 7,848 KB |
最終ジャッジ日時 | 2025-06-07 15:39:28 |
合計ジャッジ時間 | 2,445 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:62:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 62 | scanf("%s", s); | ~~~~~^~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 3171.cc: No.3171 Color Restoration - yukicoder */ #include<cstdio> #include<string> #include<vector> #include<algorithm> using namespace std; /* constant */ const int N = 3; const int MAX_K = 9; string cls[] = { "gray", "brown", "green", "cyan", "blue", "violet", "yellow" ,"orange", "red" }; const string ts[N][MAX_K] = { {"gray", "brown", "green", "cyan", "blue", "yellow", "orange", "red"}, {"gray", "green", "blue", "yellow", "red"}, {"gray", "green", "cyan", "blue", "violet", "orange", "red"} }; /* typedef */ using vi = vector<int>; using vvi = vector<vi>; /* global variables */ vi tvs[N], ccs[N]; int cids[N], ps[N]; bool es[N][N]; /* subroutines */ int colorid(const string &s) { for (int i = 0; i < MAX_K; i++) if (s == cls[i]) return i; return -1; } bool find(int cid, int j) { for (auto c: tvs[j]) if (cid == c) return true; return false; } /* main */ int main() { for (int i = 0; i < N; i++) for (int j = 0; j < MAX_K && ! ts[i][j].empty(); j++) tvs[i].push_back(colorid(ts[i][j])); for (int i = 0; i < N; i++) { char s[16]; scanf("%s", s); string w(s); cids[i] = colorid(w); for (int j = 0; j < N; j++) es[i][j] = find(cids[i], j); } for (int i = 0; i < N; i++) ps[i] = i; vvi res; do { bool ok = true; for (int i = 0; ok && i < N; i++) ok = es[i][ps[i]]; if (ok) { vi v(N); for (int i = 0; i < N; i++) v[ps[i]] = cids[i]; res.push_back(v); } } while (next_permutation(ps, ps + N)); sort(res.begin(), res.end()); res.erase(unique(res.begin(), res.end()), res.end()); if (res.size() == 1) puts("Yes"); else puts("No"); return 0; }