結果
問題 | No.2845 Birthday Pattern in Two Different Calendars |
ユーザー |
![]() |
提出日時 | 2024-08-24 01:13:50 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 360 ms / 2,000 ms |
コード長 | 1,324 bytes |
コンパイル時間 | 2,006 ms |
コンパイル使用メモリ | 199,216 KB |
最終ジャッジ日時 | 2025-02-24 00:32:24 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 22 |
ソースコード
#include <bits/stdc++.h> void dfs( int v, bool selected, std::vector<std::vector<int>> &G, std::vector<bool> &visited, std::vector<int> &selection ){ visited[v] = true; bool proceeded = false; for(int w : G[v]){ if(!visited[w]){ dfs(w, !selected, G, visited, selection); proceeded = true; } } if(selected && proceeded){ selection.emplace_back(v); } } int main(){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int T; std::cin >> T; for(int _=0;_<T;_++){ int K, M, N; std::cin >> K >> M >> N; std::vector<std::vector<int>> G(K + 1); for(int i=1;i<=K;i++){ int j = (i + M - 2) % K + 1; G[i].emplace_back(j); G[j].emplace_back(i); } std::vector<bool> visited(K + 1, 0); std::vector<int> selection; for(int i=1;i<=K;i++){ if(!visited[i]){ dfs(i, true, G, visited, selection); } } if(selection.size() >= N){ std::cout << "Yes" << std::endl; for(int i=0;i<N;i++){ std::cout << selection[i] << " \n"[i + 1 == N]; } }else{ std::cout << "No" << std::endl; } } }