結果
| 問題 |
No.850 企業コンテスト2位
|
| コンテスト | |
| ユーザー |
はまやんはまやん
|
| 提出日時 | 2019-07-06 10:53:07 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,698 bytes |
| コンパイル時間 | 1,804 ms |
| コンパイル使用メモリ | 168,760 KB |
| 実行使用メモリ | 25,604 KB |
| 平均クエリ数 | 365.32 |
| 最終ジャッジ日時 | 2024-07-16 17:39:43 |
| 合計ジャッジ時間 | 7,370 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 10 WA * 17 |
コンパイルメッセージ
main.cpp: In function 'int ask(int, int)':
main.cpp:70:17: warning: 'a' may be used uninitialized [-Wmaybe-uninitialized]
70 | if (a < b) return x;
| ^~
main.cpp:60:21: note: 'a' was declared here
60 | int a, b;
| ^
main.cpp:70:17: warning: 'b' may be used uninitialized [-Wmaybe-uninitialized]
70 | if (a < b) return x;
| ^~
main.cpp:60:24: note: 'b' was declared here
60 | int a, b;
| ^
ソースコード
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
int getrandmax() {
static uint32_t y = time(NULL);
y ^= (y << 13); y ^= (y >> 17);
y ^= (y << 5);
return abs((int)y);
}
int getrand(int l, int r) { // [l, r]
return getrandmax() % (r - l + 1) + l;
}
vector<int> makePermutation(int n, int loop = 101010) {
vector<int> v(n);
rep(i, 0, n) v[i] = i + 1;
rep(j, 0, loop) {
int a = getrand(0, n - 1);
int b = getrand(0, n - 1);
swap(v[a], v[b]);
}
return v;
}
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i @hamayanhamayan
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
int N;
//---------------------------------------------------------------------------------------------------
int forDebug[] = { -1, 2,4,1,3 };
bool isDebug = false;
int ask(int x, int y) {
if (isDebug) {
int a, b;
rep(i, 1, N + 1) if (forDebug[i] == x) {
a = i;
break;
}
rep(i, 1, N + 1) if (forDebug[i] == y) {
b = i;
break;
}
if (a < b) return x;
return y;
}
printf("? %d %d\n", x, y);
fflush(stdout);
int res; cin >> res;
return res;
}
void answer(int x) {
printf("! %d\n", x);
fflush(stdout);
}
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> N;
auto per = makePermutation(N);
int first, second;
if (ask(per[0], per[1]) == per[0]) first = per[0], second = per[1];
else first = per[1], second = per[0];
rep(i, 2, N) {
int x = per[i];
if (ask(first, x) == first) {
if (ask(second, x) == x) {
second = x;
}
}
else {
second = first;
first = x;
}
}
answer(second);
}
はまやんはまやん