# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
242518 |
2020-06-27T23:22:10 Z |
WhaleVomit |
Gap (APIO16_gap) |
C++14 |
|
76 ms |
4344 KB |
#include <bits/stdc++.h>
#include "gap.h"
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
#define MOO(i, a, b) for(int i=a; i<b; i++)
#define M00(i, a) for(int i=0; i<a; i++)
#define MOOd(i,a,b) for(int i = (b)-1; i >= a; i--)
#define M00d(i,a) for(int i = (a)-1; i>=0; i--)
#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _ << " _ " <<
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ld,ld> pd;
typedef complex<ld> cd;
/*vector<ll> vals;
ll m1 = 0;
ll m2 = 0;
void MinMax(ll s, ll t, ll& mn, ll& mx) {
m1++;
mn = (1e18)+1; mx = -1;
for(ll x: vals) {
if(s <= x && x <= t) {
mn = min(mn, x);
mx = max(mx, x);
m2++;
}
}
if(mx == -1) {
mn = -1;
}
}*/
pair<ll,ll> getMinMax(ll s, ll t) {
ll mn, mx;
MinMax(s, t, &mn, &mx);
return mp(mn, mx);
}
ll findGap(int t, int n) {
if(t == 1) {
vector<ll> nums;
ll lo = 0;
ll hi = 1e18;
int cnt = 0;
while(cnt < n) {
pair<ll,ll> p = getMinMax(lo, hi);
if(p.f == p.s) cnt++;
else cnt += 2;
nums.pb(p.f);
if(p.f != p.s) nums.pb(p.s);
lo = p.f+1;
hi = p.s-1;
}
sort(all(nums));
ll res = 0;
M00(i, n-1) {
res = max(res, nums[i+1] - nums[i]);
}
return res;
} else {
pair<ll,ll> p = getMinMax(0, 1e18);
ll small = p.f;
ll big = p.s;
ll cnt = big-small;
if(cnt < n) return 1;
ll blockcnt = n;
ll a = cnt/n;
ll b = a+1;
ll bcnt = cnt - a*n;
ll acnt = blockcnt - bcnt;
vector<pair<ll,ll>> blocks(blockcnt);
ll cur = small+1;
int numAs = 0;
M00(i, blockcnt) {
if(numAs < acnt) {
blocks[i] = mp(cur, cur+a-1);
cur += a;
numAs++;
} else {
blocks[i] = mp(cur, cur+b-1);
cur += b;
}
}
vector<pair<ll,ll>> answers(blockcnt);
M00(i, blockcnt) answers[i] = getMinMax(blocks[i].f, blocks[i].s);
ll res = 0;
ll last = small;
M00(i, blockcnt) {
if(answers[i].f != -1) {
res = max(res, answers[i].f - last);
last = answers[i].s;
}
}
return res;
}
}
/*bool test(vector<ll> v) {
vals = v;
ll ans = 0;
M00(i, sz(v)-1) {
ans = max(ans, v[i+1]-v[i]);
}
m1 = 0;
ll ans1 = findGap(1, sz(v));
if(2*m1 > sz(v)+1 || ans1 != ans) return 0;
m2 = 0;
ll ans2 = findGap(2, sz(v));
if(m2 > 3*sz(v) || ans2 != ans) return 0;
return 1;
}
int main() { FAST
vector<ll> v; v.pb(6); v.pb(7); v.pb(9);
cout << test(v) << "\n";
M00(i, 100) {
int n = (rand()%10)+2;
set<ll> s;
M00(j, n) s.insert(rand()%10);
vector<ll> v;
for(ll x: s) v.pb(x);
for(int x: v) cout << x << " ";
cout << "\n";
if(test(v)) cout << "OK\n";
else cout << "NO\n";
}
}
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
404 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
18 ms |
896 KB |
Output is correct |
17 |
Correct |
21 ms |
992 KB |
Output is correct |
18 |
Correct |
22 ms |
888 KB |
Output is correct |
19 |
Correct |
18 ms |
896 KB |
Output is correct |
20 |
Correct |
14 ms |
896 KB |
Output is correct |
21 |
Correct |
64 ms |
2288 KB |
Output is correct |
22 |
Correct |
62 ms |
2288 KB |
Output is correct |
23 |
Correct |
66 ms |
2272 KB |
Output is correct |
24 |
Correct |
69 ms |
2264 KB |
Output is correct |
25 |
Correct |
55 ms |
2276 KB |
Output is correct |
26 |
Correct |
58 ms |
2292 KB |
Output is correct |
27 |
Correct |
59 ms |
2276 KB |
Output is correct |
28 |
Correct |
69 ms |
2224 KB |
Output is correct |
29 |
Correct |
65 ms |
2300 KB |
Output is correct |
30 |
Correct |
46 ms |
2288 KB |
Output is correct |
31 |
Correct |
4 ms |
384 KB |
Output is correct |
32 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
432 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
20 ms |
1408 KB |
Output is correct |
17 |
Correct |
20 ms |
1332 KB |
Output is correct |
18 |
Correct |
24 ms |
1408 KB |
Output is correct |
19 |
Correct |
21 ms |
1408 KB |
Output is correct |
20 |
Correct |
16 ms |
1280 KB |
Output is correct |
21 |
Correct |
70 ms |
4216 KB |
Output is correct |
22 |
Correct |
70 ms |
4216 KB |
Output is correct |
23 |
Correct |
71 ms |
4216 KB |
Output is correct |
24 |
Correct |
70 ms |
4216 KB |
Output is correct |
25 |
Correct |
65 ms |
4216 KB |
Output is correct |
26 |
Correct |
76 ms |
4344 KB |
Output is correct |
27 |
Correct |
71 ms |
4192 KB |
Output is correct |
28 |
Correct |
70 ms |
4216 KB |
Output is correct |
29 |
Correct |
70 ms |
4272 KB |
Output is correct |
30 |
Correct |
40 ms |
4216 KB |
Output is correct |
31 |
Correct |
4 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |