Submission #71493

# Submission time Handle Problem Language Result Execution time Memory
71493 2018-08-24T23:11:54 Z RezwanArefin01 Aliens (IOI07_aliens) C++17
100 / 100
5 ms 572 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii; 

int n;
map<pair<ll, ll>, bool> mp; 

bool get(ll x, ll y) {
	if(x < 1 || x > n || y < 1 || y > n) return 0;
	if(mp.count({x, y})) return mp[{x, y}]; 

	cout << "examine " << x << " " << y << endl;
	string s; cin >> s;
	return mp[{x, y}] = s[0] == 't'; 
}

void ans(ll x, ll y) {
	cout << "solution " << x << " " << y << endl;
}

ll find(ll x, ll y, ll dx, ll dy) {
	ll d = 1; 
	while(get(x + dx * d, y + dy * d)) d <<= 1; 
	ll lo = d >> 1, hi = d, idx; 
	while(lo <= hi) {
		ll mid = lo + hi >> 1; 
		if(get(x + dx * mid, y + dy * mid))
			lo = mid + 1, idx = mid; 
		else hi = mid - 1; 
	} return idx;
}
int main(int argc, char const *argv[]) {
	cin >> n;	
	ll x0, y0; cin >> x0 >> y0; 

	ll xr = x0 + find(x0, y0, +1, 0); 
	ll xl = x0 - find(x0, y0, -1, 0);
	ll yl = y0 + find(x0, y0, 0, +1); 

	ll M = xr - xl + 1; 
	ll yr = yl - M + 1;

	ll xc = xr + xl >> 1, yc = yl + yr >> 1; 

	while(get(xc - 2 * M, yc)) xc -= 2 * M; 
	while(get(xc, yc - 2 * M)) yc -= 2 * M; 
	while(get(xc - M, yc - M)) xc -= M, yc -= M; 

	xc += 2 * M;
	yc += 2 * M;
	ans(xc, yc);
}

Compilation message

aliens.cpp: In function 'll find(ll, ll, ll, ll)':
aliens.cpp:28:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   ll mid = lo + hi >> 1; 
            ~~~^~~~
aliens.cpp: In function 'int main(int, const char**)':
aliens.cpp:45:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  ll xc = xr + xl >> 1, yc = yl + yr >> 1; 
          ~~~^~~~
aliens.cpp:45:32: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  ll xc = xr + xl >> 1, yc = yl + yr >> 1; 
                             ~~~^~~~
aliens.cpp: In function 'll find(ll, ll, ll, ll)':
aliens.cpp:32:11: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
  } return idx;
           ^~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 296 KB Output is correct
2 Correct 2 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 388 KB Output is correct
2 Correct 3 ms 420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 488 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 500 KB Output is correct
2 Correct 3 ms 556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 556 KB Output is correct
2 Correct 2 ms 556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 556 KB Output is correct
2 Correct 3 ms 556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 556 KB Output is correct
2 Correct 2 ms 556 KB Output is correct
3 Correct 2 ms 564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 564 KB Output is correct
2 Correct 3 ms 568 KB Output is correct
3 Correct 4 ms 568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 568 KB Output is correct
2 Correct 4 ms 568 KB Output is correct
3 Correct 2 ms 568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 568 KB Output is correct
2 Correct 4 ms 568 KB Output is correct
3 Correct 5 ms 572 KB Output is correct