結果
| 問題 |
No.2845 Birthday Pattern in Two Different Calendars
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-08-23 21:52:08 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 112 ms / 2,000 ms |
| コード長 | 1,287 bytes |
| コンパイル時間 | 2,061 ms |
| コンパイル使用メモリ | 203,820 KB |
| 最終ジャッジ日時 | 2025-02-23 23:41:35 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 22 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T; cin >> T;
while(T--){
int K,M,N; cin >> K >> M >> N; M--;
if(M == 0){cout << "No\n"; continue;}
vector<vector<int>> Graph(K);
for(int i=0; i<K; i++) Graph.at(i).push_back((i+M)%K);
vector<bool> already(K);
vector<int> answer;
for(int i=0; i<K; i++){
if(already.at(i)) continue;
already.at(i) = true;
queue<int> Q; Q.push(i);
bool ok = true;
while(Q.size()){
int pos = Q.front(); Q.pop();
if(ok) answer.push_back(pos),ok = false;
else ok = true;
for(auto to : Graph.at(pos)){
if(already.at(to)){
if(ok == false) answer.pop_back();
break;
}
Q.push(to); already.at(to) = true;
}
}
}
while(answer.size() > N) answer.pop_back();
if(answer.size() < N) cout << "No\n";
else{
cout << "Yes\n";
for(int i=0; i<N; i++) cout << answer.at(i)+1 << (i==N-1?"\n":" ");
}
}
}