Submission #15279

# Submission time Handle Problem Language Result Execution time Memory
15279 2015-07-12T05:16:20 Z myungwoo 로봇 심판의 님 게임 (kriii3_F) C++14
0 / 79
104 ms 5616 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
typedef long long lld;

int N, M, K;
int A[21], G[21];
vector <int> P, Q;
vector <int> C;

inline lld invalid(lld n)
{
	return C[n];
}

inline lld get_grundy(lld n)
{
	return n - invalid(n);
}

inline lld get_number_with_grundy(lld g, lld n)
{
	lld s = 1, e = n - 1, ret = 0;
	while (s <= e){
		lld m = (s+e) >> 1;
		if (m - C[m] >= g) e = m-1, ret = m;
		else s = m+1;
	}
	return ret;
}

inline lld get_number_robot_delete(lld n)
{
	lld s = 0, e = n - 2, ret = n - 1;
	lld v = invalid(n - 1);
	while (s <= e){
		lld m = (s+e) >> 1;
		if (C[m] >= v) e = m-1, ret = m;
		else s = m+1;
	}
	return ret;
}

int main()
{
	int V = 0;
	scanf("%d%d%d", &N, &M, &K);
	for (int i=0;i<N;i++){
		int x; scanf("%d", &x); P.pb(x);
	}
	for (int i=0;i<M;i++){
		int x; scanf("%d", &x); Q.pb(x);
	}
	for (int i=1;i<=K;i++){
		scanf("%d", A+i);
		V = max(V, A[i]);
	}
	C.resize(V+1, 0);
	for (int i=1;i<=V;i++){
		C[i] = C[i-1];
		bool sw = 0;
		for (int j=0;j<N;j++){
			if (i % P[j] == 0) sw = 1;
		}
		for (int j=0;j<M;j++){
			if (i % Q[j] != 0) sw = 1;
		}
		if (sw) C[i]++;
	}
	lld x = 0;
	for (int i=1;i<=K;i++){
		G[i] = get_grundy(A[i]);
		x ^= G[i];
	}
	for (int i=1;i<=K;i++){
		if (!G[i]){ puts("0 0"); continue; }
		lld ox = x ^ G[i];
		lld p, q;
		if (ox){
			if (ox < G[i]) p = 1, q = A[i] - get_number_with_grundy(ox, A[i]);
			else p = q = 0;
		}else{
			p = A[i] - G[i];
			if (p) q = A[i] - get_number_robot_delete(A[i]);
			else q = 0;
		}
		printf("%lld %lld\n", p, q);
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 104 ms 5616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -