結果
| 問題 |
No.850 企業コンテスト2位
|
| コンテスト | |
| ユーザー |
tarattata1
|
| 提出日時 | 2019-07-06 15:24:08 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 31 ms / 2,000 ms |
| コード長 | 1,785 bytes |
| コンパイル時間 | 1,161 ms |
| コンパイル使用メモリ | 73,664 KB |
| 実行使用メモリ | 25,220 KB |
| 平均クエリ数 | 200.11 |
| 最終ジャッジ日時 | 2024-07-16 17:40:22 |
| 合計ジャッジ時間 | 3,142 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 27 |
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:27:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
27 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:48:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
48 | scanf("%d", &ans);
| ~~~~~^~~~~~~~~~~~
main.cpp:73:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
73 | scanf("%d", &ans);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996)
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;
int main(int argc, char* argv[])
{
int n;
scanf("%d", &n);
vector<int> a(n, -1); // 各人が負けた相手を記録
vector<int> b; // 勝ち残った人たち
int i,j;
for(i=0; i<n; i++) b.push_back(i);
for(i=0; i<10; i++) {
if(b.size()==1) break;
vector<int> c;
int siz=(int)b.size();
for(j=0; j<siz; j+=2) {
if(j==siz-1) {
c.push_back(b[j]);
}
else {
printf("? %d %d\n", b[j]+1, b[j+1]+1);
fflush(stdout);
int ans;
scanf("%d", &ans);
if(ans==b[j]+1) {
c.push_back(b[j]);
a[b[j+1]]=b[j];
}
else {
c.push_back(b[j+1]);
a[b[j]]=b[j+1];
}
}
}
b.swap(c);
}
vector<int> d;
int win = b[0];
for(i=0; i<n; i++) {
if(a[i]==win) d.push_back(i);
}
int sec=d[0];
for(i=1; i<(int)d.size(); i++) {
printf("? %d %d\n", sec+1, d[i]+1);
fflush(stdout);
int ans;
scanf("%d", &ans);
if(ans!=sec+1) {
sec = d[i];
}
}
printf("! %d\n", sec+1);
return 0;
}
tarattata1