# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
39804 |
2018-01-19T06:41:20 Z |
14kg |
Gap (APIO16_gap) |
C++11 |
|
2000 ms |
169828 KB |
#include "gap.h"
#include <set>
#define NUM_MAX 1000000000000000000
#define R_MAX 1152921504606846976
#define max2(x,y) (x>y?x:y)
#define min2(x,y) (x<y?x:y)
using namespace std;
int n;
set<long long> S;
set<pair<long long,long long> > pass;
long long f1() {
long long l = 0, r = NUM_MAX;
long long t1, t2, res = 0;
while (l <= r) {
MinMax(l, r, &t1, &t2);
if (t1 < 0) break;
S.insert(l = t1), S.insert(r = t2);
l++, r--;
if (S.size() == n) break;
}
t1 = NUM_MAX;
for (auto i : S) res = max2(res, i - t1), t1 = i;
return res;
}
long long get_pass(long long x) {
set<pair<long long, long long>>::iterator it = pass.upper_bound({ x,-1 });
if (it == pass.end()) return -1;
if (it->first == x) return it->second;
return -1;
}
bool Can(long long len) {
long long back_MAX = NUM_MAX;
long long t1, t2;
for (long long s = 0; s <= NUM_MAX; s += len) {
t2 = get_pass(s);
if (t2 > 0) { s = t2 - len; continue; }
MinMax(s, min2(NUM_MAX, s + len - 1), &t1, &t2);
if (t1 < 0) { pass.insert({ s,s + len }); continue; }
if (t1 - back_MAX >= len) return true;
back_MAX = t2;
} return false;
}
long long f2() {
long long l = 1, r = R_MAX, mid;
while (l <= r) {
mid = (l + r) / 2;
if (Can(mid)) l = mid + 1;
else r = mid - 1;
} return l - 1;
}
long long findGap(int T, int _n) {
n = _n;
if (T == 1) return f1();
else return f2();
}
Compilation message
gap.cpp: In function 'long long int f1()':
gap.cpp:23:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (S.size() == n) break;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4300 KB |
Output is correct |
2 |
Correct |
0 ms |
4300 KB |
Output is correct |
3 |
Correct |
0 ms |
4300 KB |
Output is correct |
4 |
Correct |
0 ms |
4300 KB |
Output is correct |
5 |
Correct |
0 ms |
4300 KB |
Output is correct |
6 |
Correct |
0 ms |
4300 KB |
Output is correct |
7 |
Correct |
0 ms |
4300 KB |
Output is correct |
8 |
Correct |
0 ms |
4300 KB |
Output is correct |
9 |
Correct |
0 ms |
4300 KB |
Output is correct |
10 |
Correct |
0 ms |
4300 KB |
Output is correct |
11 |
Correct |
1 ms |
4432 KB |
Output is correct |
12 |
Correct |
1 ms |
4432 KB |
Output is correct |
13 |
Correct |
2 ms |
4432 KB |
Output is correct |
14 |
Correct |
0 ms |
4432 KB |
Output is correct |
15 |
Correct |
1 ms |
4432 KB |
Output is correct |
16 |
Correct |
18 ms |
5488 KB |
Output is correct |
17 |
Correct |
18 ms |
5488 KB |
Output is correct |
18 |
Correct |
18 ms |
5488 KB |
Output is correct |
19 |
Correct |
21 ms |
5488 KB |
Output is correct |
20 |
Correct |
17 ms |
5488 KB |
Output is correct |
21 |
Correct |
87 ms |
9052 KB |
Output is correct |
22 |
Correct |
80 ms |
9052 KB |
Output is correct |
23 |
Correct |
93 ms |
9052 KB |
Output is correct |
24 |
Correct |
90 ms |
9052 KB |
Output is correct |
25 |
Correct |
81 ms |
9052 KB |
Output is correct |
26 |
Correct |
83 ms |
9052 KB |
Output is correct |
27 |
Correct |
84 ms |
9052 KB |
Output is correct |
28 |
Correct |
86 ms |
9052 KB |
Output is correct |
29 |
Correct |
87 ms |
9052 KB |
Output is correct |
30 |
Correct |
75 ms |
9052 KB |
Output is correct |
31 |
Correct |
0 ms |
4300 KB |
Output is correct |
32 |
Correct |
0 ms |
4300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
4300 KB |
Partially correct |
2 |
Partially correct |
0 ms |
4300 KB |
Partially correct |
3 |
Partially correct |
0 ms |
4300 KB |
Partially correct |
4 |
Partially correct |
0 ms |
4300 KB |
Partially correct |
5 |
Execution timed out |
2000 ms |
169828 KB |
Execution timed out |
6 |
Partially correct |
0 ms |
4300 KB |
Partially correct |
7 |
Partially correct |
0 ms |
4300 KB |
Partially correct |
8 |
Partially correct |
0 ms |
4300 KB |
Partially correct |
9 |
Partially correct |
0 ms |
4300 KB |
Partially correct |
10 |
Execution timed out |
2000 ms |
162832 KB |
Execution timed out |
11 |
Partially correct |
5 ms |
4300 KB |
Partially correct |
12 |
Partially correct |
6 ms |
4300 KB |
Partially correct |
13 |
Partially correct |
6 ms |
4300 KB |
Partially correct |
14 |
Partially correct |
4 ms |
4300 KB |
Partially correct |
15 |
Execution timed out |
2000 ms |
157156 KB |
Execution timed out |
16 |
Partially correct |
89 ms |
4300 KB |
Partially correct |
17 |
Partially correct |
69 ms |
4300 KB |
Partially correct |
18 |
Partially correct |
70 ms |
4300 KB |
Partially correct |
19 |
Partially correct |
62 ms |
4300 KB |
Partially correct |
20 |
Execution timed out |
2000 ms |
147520 KB |
Execution timed out |
21 |
Partially correct |
283 ms |
4300 KB |
Partially correct |
22 |
Partially correct |
264 ms |
4300 KB |
Partially correct |
23 |
Partially correct |
289 ms |
4300 KB |
Partially correct |
24 |
Partially correct |
224 ms |
4300 KB |
Partially correct |
25 |
Execution timed out |
2000 ms |
137356 KB |
Execution timed out |
26 |
Partially correct |
237 ms |
4300 KB |
Partially correct |
27 |
Partially correct |
301 ms |
4300 KB |
Partially correct |
28 |
Partially correct |
304 ms |
4300 KB |
Partially correct |
29 |
Partially correct |
292 ms |
4300 KB |
Partially correct |
30 |
Execution timed out |
2000 ms |
141448 KB |
Execution timed out |
31 |
Partially correct |
0 ms |
4300 KB |
Partially correct |
32 |
Partially correct |
0 ms |
4300 KB |
Partially correct |