# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
15507 |
2015-07-12T08:39:24 Z |
xhae |
로봇 심판의 님 게임 (kriii3_F) |
C++14 |
|
460 ms |
2236 KB |
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <set>
using namespace std;
int N, M, K;
vector<long long> P, Q, cnt;
vector<long long> lcms;
long long calc(long long num) {
long long res = 0;
for (int bit = 0; bit < (1 << N); bit ++) {
for (int bit2 = 1; bit2 < (1 << M); bit2 ++) {
long long val = lcms[bit * (1<<M) + bit2];
if (val > 0) res += num / val;
else if (val < 0) res -= num / (-val);
}
}
return res;
}
int main()
{
cin >> N >> M >> K;
P.resize(N);
Q.resize(M);
cnt.resize(K);
for (int i=0; i<N; i++) cin >> P[i];
for (int i=0; i<M; i++) cin >> Q[i];
for (int i=0; i<K; i++) cin >> cnt[i];
lcms.resize(1<<(N+M));
for (int bit = 0; bit < (1 << N); bit ++) {
int flip = 1;
long long lcm = 1;
for (int i=0; i<N; i++)
if (bit&(1<<i)) {
lcm = lcm * P[i] / __gcd(lcm, 0LL + P[i]);
flip = -flip;
if (lcm > 1000000000000LL) break;
}
if (lcm > 1000000000000LL) continue;
for (int bit2 = 1; bit2 < (1 << M); bit2 ++) {
int flip2 = -flip;
long long lcm2 = lcm;
for (int i=0; i<M; i++) {
if (bit2&(1<<i)) {
lcm2 = lcm2 * Q[i] / __gcd(lcm2, 0LL + Q[i]);
flip2 = -flip2;
if (lcm2 > 1000000000000LL) break;
}
}
lcms[bit * (1<<M) + bit2] = flip2 * lcm2;
}
}
long long xx = 0;
for (int i=0; i<K; i++)
if (calc(cnt[i]) - calc(cnt[i] - 1) > 0)
xx ^= calc(cnt[i]);
for (int i=0; i<K; i++) {
long long ra = 0, rb = 0;
if (calc(cnt[i]) - calc(cnt[i] - 1) > 0) {
long long my_cnt = calc(cnt[i]);
long long target = my_cnt ^ xx;
if (target < my_cnt) {
if (target == 0) {
ra = cnt[i] + 1 - my_cnt;
long long ll = 0;
long long rr = cnt[i] - 1;
while (ll < rr) {
long long mid = (ll + rr) / 2;
if (my_cnt - calc(mid) != cnt[i] - mid) ll = mid + 1;
else rr = mid;
}
rb = cnt[i] - ll;
} else {
ra = 1;
long long ll = 0;
long long rr = cnt[i] - 1;
while (ll < rr) {
long long mid = (ll + rr) / 2;
if (calc(mid) < target) ll = mid + 1;
else rr = mid;
}
rb = cnt[i] - ll;
}
}
}
cout << ra << " " << rb << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
398 ms |
2236 KB |
Output is correct |
2 |
Correct |
328 ms |
2236 KB |
Output is correct |
3 |
Correct |
246 ms |
2236 KB |
Output is correct |
4 |
Correct |
313 ms |
2236 KB |
Output is correct |
5 |
Correct |
340 ms |
2236 KB |
Output is correct |
6 |
Correct |
137 ms |
2236 KB |
Output is correct |
7 |
Correct |
290 ms |
2236 KB |
Output is correct |
8 |
Correct |
237 ms |
2236 KB |
Output is correct |
9 |
Correct |
285 ms |
2236 KB |
Output is correct |
10 |
Correct |
163 ms |
2236 KB |
Output is correct |
11 |
Correct |
27 ms |
2236 KB |
Output is correct |
12 |
Correct |
42 ms |
2236 KB |
Output is correct |
13 |
Correct |
46 ms |
2236 KB |
Output is correct |
14 |
Correct |
36 ms |
2236 KB |
Output is correct |
15 |
Correct |
47 ms |
2236 KB |
Output is correct |
16 |
Correct |
59 ms |
2236 KB |
Output is correct |
17 |
Correct |
45 ms |
2236 KB |
Output is correct |
18 |
Correct |
34 ms |
2236 KB |
Output is correct |
19 |
Correct |
31 ms |
2236 KB |
Output is correct |
20 |
Correct |
40 ms |
2236 KB |
Output is correct |
21 |
Correct |
43 ms |
2236 KB |
Output is correct |
22 |
Correct |
27 ms |
2236 KB |
Output is correct |
23 |
Correct |
23 ms |
2236 KB |
Output is correct |
24 |
Correct |
107 ms |
2236 KB |
Output is correct |
25 |
Correct |
304 ms |
2236 KB |
Output is correct |
26 |
Correct |
100 ms |
2236 KB |
Output is correct |
27 |
Correct |
460 ms |
2236 KB |
Output is correct |
28 |
Correct |
46 ms |
2236 KB |
Output is correct |
29 |
Correct |
58 ms |
2236 KB |
Output is correct |
30 |
Correct |
26 ms |
2236 KB |
Output is correct |
31 |
Correct |
0 ms |
1720 KB |
Output is correct |
32 |
Correct |
0 ms |
1720 KB |
Output is correct |
33 |
Correct |
0 ms |
1720 KB |
Output is correct |
34 |
Correct |
0 ms |
1720 KB |
Output is correct |
35 |
Correct |
1 ms |
1720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1720 KB |
Output is correct |
2 |
Correct |
0 ms |
1720 KB |
Output is correct |
3 |
Correct |
41 ms |
1720 KB |
Output is correct |
4 |
Correct |
448 ms |
2236 KB |
Output is correct |
5 |
Correct |
241 ms |
2236 KB |
Output is correct |
6 |
Correct |
49 ms |
2236 KB |
Output is correct |
7 |
Correct |
59 ms |
2236 KB |
Output is correct |
8 |
Correct |
68 ms |
2236 KB |
Output is correct |
9 |
Correct |
66 ms |
2236 KB |
Output is correct |
10 |
Correct |
59 ms |
2236 KB |
Output is correct |