답안 #472752

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
472752 2021-09-14T09:28:57 Z flappybird Cup of Jamshid (IOI17_cup) C++14
100 / 100
1 ms 204 KB
#include "cup.h"
#include <bits/stdc++.h>
using namespace std;
typedef int ll;

ll e = 30;

vector<int> find_cup() {
	vector<ll> ans(2);
	ll a, b;
	a = b = 0;
	ll i;
	ll res = ask_shahrasb(-1 << 29, -1 << 29);
	for (i = e; i >= 1; i--) {
		ll loc = 1 << (i - 1);
		if (i == e) {
			if (res & loc) {
				ll r = -1;
				ll r1 = ask_shahrasb(a, b - 1) & loc;
				if (r1) r = 0;
				if (r == -1) r = ask_shahrasb(a - loc, b - 1) & loc;
				if (r) a += loc / 2, b -= (loc + 1) / 2;
				else a -= (loc + 1) / 2, b += loc / 2;
			}
			else {
				ll r = -1;
				ll r1 = ask_shahrasb(a - 1, b - 1) & loc;
				if (r1) r = 0;
				if (r == -1) r = ask_shahrasb(a - loc, b) & loc;
				if (r) a += loc / 2, b += loc / 2;
				else a -= (loc + 1) / 2, b -= (loc + 1) / 2;
			}
		}
		else {
			if (res & loc) {
				ll r = ask_shahrasb(a - loc * 2, b);
				if (r & (loc * 2)) a += loc / 2, b -= (loc + 1) / 2;
				else a -= (loc + 1) / 2, b += loc / 2;
			}
			else {
				ll r = ask_shahrasb(a - loc * 2, b);
				if (r & (loc * 2)) a += loc / 2, b += loc / 2;
				else a -= (loc + 1) / 2, b -= (loc + 1) / 2;
			}
		}
	}
	ans[0] = a;
	ans[1] = b;
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct