結果

問題 No.2845 Birthday Pattern in Two Different Calendars
ユーザー tnakao0123
提出日時 2024-08-24 17:16:56
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 991 bytes
コンパイル時間 312 ms
コンパイル使用メモリ 41,216 KB
最終ジャッジ日時 2025-02-24 00:39:52
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:28:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   28 |   scanf("%d", &tn);
      |   ~~~~~^~~~~~~~~~~
main.cpp:32:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |     scanf("%d%d%d", &k, &m, &n);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2845.cc:  No.2845 Birthday Pattern in Two Different Calendars - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_K = 200000;

/* typedef */

/* global variables */

bool used[MAX_K], fs[MAX_K];
int as[MAX_K];

/* subroutines */

/* main */

int main() {
  int tn;
  scanf("%d", &tn);

  while (tn--) {
    int k, m, n;
    scanf("%d%d%d", &k, &m, &n);
    m--;
    if (m == 0) { puts("No"); continue; }
    
    fill(fs, fs + k, false);
    fill(used, used + k, false);
    int l = 0;
    
    for (int st = 0; st < k; st++)
      if (! fs[st]) {
	for (int u = st; ! fs[u];) {
	  fs[u] = true;
	  int v = (u + m) % k;
	  if (! used[u] && ! used[v]) {
	    as[l++] = u;
	    used[u] = used[v] = true;
	  }
	  u = v;
	}
      }

    if (l >= n) {
      puts("Yes");
      for (int i = 0; i < n; i++)
	printf("%d%c", as[i] + 1, (i + 1 < n) ? ' ' : '\n');
    }
    else
      puts("No");
  }

  return 0;
}
0