結果

問題 No.2828 Remainder Game
ユーザー tnakao0123
提出日時 2024-08-05 15:47:45
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 814 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 40,828 KB
最終ジャッジ日時 2025-02-23 21:04:11
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int query(int)’:
main.cpp:33:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   33 |   scanf("%d", &c);
      |   ~~~~~^~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:41:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   41 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2828.cc:  No.2828 Remainder Game - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 1000;
const int MAX_K = 1024;

/* typedef */

/* global variables */

int rs[MAX_K];

/* subroutines */

int query(int m) {
  int k = 0;
  for (int i = m / 2; i < m; i++) rs[k++] = i;
  printf("%d %d\n", m, k);
  for (int i = 0; i < k; i++)
    printf("%d%c", rs[i], (i + 1 < k) ? ' ' : '\n');
  fflush(stdout);

  int c;
  scanf("%d", &c);
  return c;
}

/* main */

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

  int maxm = 1;
  while (maxm <= n) maxm <<= 1;

  int sum = 0;
  for (int m = 2, bi = 1; m <= maxm; m <<= 1, bi <<= 1) {
    int c = query(m);
    sum += bi * c;
  }

  printf("0 1\n%d\n", sum); fflush(stdout);
  
  return 0;
}
0