Submission #2120437


Source Code Expand

#include <stdio.h>
#pragma warning(disable:4996)
//FILE *in = fopen("input.txt", "r"), *out = fopen("output.txt", "w");
FILE *in = stdin, *out = stdout;
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
#define INF 0x7fffffff
#define NM 100005
#define MOD 1000000007
#define FOR(i,n,m) for (int i=(n);i<=(m);i++)
#define si(n) fscanf(in,"%d",&n)
#define sd(n) fscanf(in,"%lf",&n)
typedef long long int ll;

int ans=123;
char test(ll X) {
	//*
	fprintf(out, "? %lld\n", X);
	char ch[5]; fscanf(in, "%s", ch);
	fflush(stdout);//*/
	return ch[0];
}
void Find(int X) {
	fprintf(out, "! %d\n", X);
}

int getLen() {
	int L = 0, R = 8, len = 9;
	while (L <= R) {
		int m = (L + R) >> 1;
		int X = 1;
		FOR(i, 1, m) X *= 10;
		if (test(X) == 'N') {
			len = min(len, m);
			R = m - 1;
		}
		else {
			L = m + 1;
		}
	}
	/*for (ll X = 1; len < 9; len++, X *= 10) {
		if (test(X) == 'N') {
			return len;
		}
	}*/
	return len;
}
int main() {
	int len = getLen();
	if (len == 9 && test(1000000000) == 'Y') { // 10^k 꼴 or 9자리
		len = 0;
		for (ll X = 2; len <= 9; len++, X *= 10) {
			char ch = test(X);
			if (ch == 'Y') {
				Find(X / 2);
				return 0;
			}
		}
	}
	int ans = 0;
	FOR(k, 1, len - 1) {
		int L = 0, R = 9, v = 9;
		if (k == 1) L = 1;
		while(L<=R){
			int m = (L + R) >> 1;
			int X = ans * 10 + m;
			if (test(X) == 'N') {
				v = min(v, m - 1);
				R = m - 1;
			}
			else {
				L = m + 1;
			}
		}
		ans = ans * 10 + v;
	}
	{ // last digit
		int L = 0, R = 9, v = -1;
		if (len == 1) L = 1;
		FOR(i, L, R) {
			ll X = ((ll)ans * 10 + i) * 10;
			if (test(X) == 'Y') {
				Find(ans * 10 + i);
				return 0;
			}
		}
	}
	return 0;
}

Submission Info

Submission Time
Task E - Awkward Response
User rhs0266
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1763 Byte
Status TLE
Exec Time 2103 ms
Memory 504 KB

Compile Error

./Main.cpp: In function ‘char test(ll)’:
./Main.cpp:21:34: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  char ch[5]; fscanf(in, "%s", ch);
                                  ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 800
Status
TLE × 1
TLE × 40
Set Name Test Cases
Sample 00_example_01.txt
All 00_example_01.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt
Case Name Status Exec Time Memory
00_example_01.txt TLE 2103 ms 504 KB
01.txt TLE 2103 ms 500 KB
02.txt TLE 2103 ms 500 KB
03.txt TLE 2103 ms 504 KB
04.txt TLE 2103 ms 504 KB
05.txt TLE 2103 ms 500 KB
06.txt TLE 2103 ms 500 KB
07.txt TLE 2103 ms 496 KB
08.txt TLE 2103 ms 500 KB
09.txt TLE 2103 ms 504 KB
10.txt TLE 2103 ms 500 KB
11.txt TLE 2103 ms 504 KB
12.txt TLE 2103 ms 504 KB
13.txt TLE 2103 ms 504 KB
14.txt TLE 2103 ms 500 KB
15.txt TLE 2103 ms 500 KB
16.txt TLE 2103 ms 504 KB
17.txt TLE 2103 ms 500 KB
18.txt TLE 2103 ms 504 KB
19.txt TLE 2103 ms 500 KB
20.txt TLE 2103 ms 504 KB
21.txt TLE 2103 ms 500 KB
22.txt TLE 2103 ms 504 KB
23.txt TLE 2103 ms 500 KB
24.txt TLE 2103 ms 500 KB
25.txt TLE 2103 ms 504 KB
26.txt TLE 2103 ms 504 KB
27.txt TLE 2103 ms 500 KB
28.txt TLE 2103 ms 504 KB
29.txt TLE 2103 ms 500 KB
30.txt TLE 2103 ms 500 KB
31.txt TLE 2103 ms 504 KB
32.txt TLE 2103 ms 500 KB
33.txt TLE 2103 ms 504 KB
34.txt TLE 2103 ms 500 KB
35.txt TLE 2103 ms 500 KB
36.txt TLE 2103 ms 504 KB
37.txt TLE 2103 ms 500 KB
38.txt TLE 2103 ms 500 KB
39.txt TLE 2103 ms 504 KB