結果
| 問題 |
No.850 企業コンテスト2位
|
| コンテスト | |
| ユーザー |
lowr
|
| 提出日時 | 2019-08-16 20:35:10 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 30 ms / 2,000 ms |
| コード長 | 1,146 bytes |
| コンパイル時間 | 1,937 ms |
| コンパイル使用メモリ | 199,924 KB |
| 最終ジャッジ日時 | 2025-01-07 12:09:00 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 27 |
コンパイルメッセージ
main.cpp: In function ‘int ask(int, int)’:
main.cpp:8:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
8 | scanf("%d", &ret);
| ~~~~~^~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:14:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using i64 = long long;
int ask(int a, int b) {
printf("? %d %d\n", a, b);
fflush(stdout);
int ret;
scanf("%d", &ret);
return ret;
}
int main() {
int n;
scanf("%d", &n);
std::vector<int> cs;
for (int i = 1; i <= n; i++) cs.push_back(i);
std::vector<std::vector<int>> wl(n + 1, std::vector<int>(n + 1));
while (cs.size() > 1) {
std::vector<int> next;
for (int i = 1; 2 * i - 1 < cs.size(); i++) {
int w = ask(cs[2 * i - 2], cs[2 * i - 1]);
int l = cs[2 * i - 2] ^ cs[2 * i - 1] ^ w;
next.push_back(w);
wl[w][l] = 1;
wl[l][w] = -1;
}
if (cs.size() & 1) next.push_back(cs.back());
std::swap(next, cs);
}
int f = cs.front();
std::vector<int> cand;
for (int i = 1; i <= n; i++) if (wl[f][i] > 0) cand.push_back(i);
while (cand.size() > 1) {
std::vector<int> next;
for (int i = 1; 2 * i - 1 < cand.size(); i++) {
next.push_back(ask(cand[2 * i - 2], cand[2 * i - 1]));
}
if (cand.size() & 1) next.push_back(cand.back());
std::swap(next, cand);
}
printf("! %d\n", cand.front());
fflush(stdout);
return 0;
}
lowr