結果
問題 |
No.2845 Birthday Pattern in Two Different Calendars
|
ユーザー |
![]() |
提出日時 | 2024-08-23 22:31:54 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,386 bytes |
コンパイル時間 | 1,099 ms |
コンパイル使用メモリ | 100,060 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-08-23 22:31:59 |
合計ジャッジ時間 | 4,873 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 7 WA * 15 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; void solve() { int k, m, n; cin >> k >> m >> n; if (n * 2 > k || m == 1) { cout << "No" << endl; return; } auto cal = [&](int d) -> int {return (d + m - 2) % k + 1;}; vector<int> ans, used(k + 1); int now = 1; while (ans.size() < n) { while (now <= k && used[now]) ++now; if (now > k) break; int d = cal(now); if (!used[d]) { used[now] = 1; used[d] = 1; ans.push_back(now); } else ++now; } if (ans.size() == n) { cout << "Yes" << endl; for (auto v : ans) cout << v << ' '; cout << endl; return; } ans.clear(); used.assign(k + 1, 0); for (now = 1; now <= k; now += m) { int d = cal(now); if (d < now || ans.size() >= n) break; if (!used[now] && !used[d]) { used[now] = 1; used[d] = 1; ans.push_back(now); } } now = 1; while (ans.size() < n) { while (now <= k && used[now]) ++now; if (now > k) break; int d = cal(now); if (!used[d]) { used[now] = 1; used[d] = 1; ans.push_back(now); } else ++now; } if (ans.size() == n) { cout << "Yes" << endl; for (auto v : ans) cout << v << ' '; cout << endl; } else cout << "No" << endl; } int main() { int t; cin >> t; while (t--) solve(); }