結果

問題 No.3246 80% Accuracy Calculator
ユーザー tnakao0123
提出日時 2025-08-26 09:24:13
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,330 bytes
コンパイル時間 510 ms
コンパイル使用メモリ 62,616 KB
実行使用メモリ 26,228 KB
平均クエリ数 472.44
最終ジャッジ日時 2025-08-26 09:24:18
合計ジャッジ時間 4,493 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 42 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int query1(int)’:
main.cpp:32:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |   scanf("%d", &r);
      |   ~~~~~^~~~~~~~~~
main.cpp: In function ‘int query2(int, int, int)’:
main.cpp:41:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   41 |   scanf("%d", &r);
      |   ~~~~~^~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 3246.cc:  No.3246 80% Accuracy Calculator - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<map>
#include<algorithm>

using namespace std;

/* constant */

const int TC = 10;
enum {A, B, C};

/* typedef */

using mii = map<int,int>;

/* global variables */

int vs[3];

/* subroutines */

int query1(int c) {
  printf("? %c\n", 'A' + c); fflush(stdout);

  int r;
  scanf("%d", &r);
  if (r < 0) exit(0);
  return r;
}

int query2(int c0, int c1, int c2) {
  printf("+ %c %c %c\n", 'A' + c0, 'A' + c1, 'A' + c2); fflush(stdout);

  int r;
  scanf("%d", &r);
  if (r < 0) exit(0);
  return r;
}

int check(int c) {
  mii vcs;
  for (;;) {
    int r = query1(c);
    if (++vcs[r] >= TC) return r;
  }
  return -1;
}

void add(int c0, int c1, int c2) {
  int s = vs[c0] + vs[c1];
  for (;;) {
    query2(c0, c1, c2);
    if (check(c2) == s) break;
  }
  vs[c2] = s;
}

void answer(int c) {
  printf("! %c\n", 'A' + c); fflush(stdout);
}

/* main */

int main() {
  int x = check(A);
  int y = check(B);

  vs[A] = x, vs[B] = y, vs[C] = 0;
  add(C, C, B);

  int cx = A, cp = B, ct = C;
  while (y > 0) {
    if (y & 1) {
      add(cp, cx, ct);
      swap(cp, ct);
    }
    add(cx, cx, ct);
    swap(cx, ct);
    y >>= 1;
  }

  answer(cp);

  //for (int i = 0; i < 1e9; i++);
  return 0;
}
0