結果
| 問題 |
No.850 企業コンテスト2位
|
| コンテスト | |
| ユーザー |
satashun
|
| 提出日時 | 2019-07-05 21:53:26 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,527 bytes |
| コンパイル時間 | 1,658 ms |
| コンパイル使用メモリ | 171,496 KB |
| 実行使用メモリ | 25,604 KB |
| 平均クエリ数 | 197.50 |
| 最終ジャッジ日時 | 2024-07-16 17:17:43 |
| 合計ジャッジ時間 | 8,640 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 3 WA * 24 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }
template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
os<<"("<<p.first<<","<<p.second<<")";
return os;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
os<<"{";
rep(i, v.size()) {
if (i) os<<",";
os<<v[i];
}
os<<"}";
return os;
}
bool ask(int x, int y) {
printf("? %d %d\n", x + 1, y + 1);
fflush(stdout);
int res;
scanf("%d", &res); --res;
return res == x;
}
void answer(int x) {
printf("! %d\n", x + 1);
fflush(stdout);
}
int w[310][310];
int rem(vi vec) {
while (vec.size() >= 2) {
vi nx;
for (int i = 0; i < (int)vec.size() / 2; ++i) {
int x = vec[i * 2];
int y = vec[i * 2 + 1];
bool f = ask(x, y);
if (f) {
w[x][y] = 1;
w[y][x] = 0;
nx.pb(x);
} else {
w[y][x] = 1;
w[x][y] = 0;
nx.pb(y);
}
}
vec.swap(nx);
}
return vec[0];
}
int main() {
int N; cin >> N;
memset(w, -1, sizeof(w));
vi vec; rep(i, N) vec.pb(i);
int p = rem(vec);
vi cand;
rep(i, N) if (w[p][i] == 1) {
cand.pb(i);
}
int q = rem(cand);
answer(q);
return 0;
}
satashun