Submission #183977

# Submission time Handle Problem Language Result Execution time Memory
183977 2020-01-10T09:55:09 Z dndhk Gap (APIO16_gap) C++14
70 / 100
89 ms 3308 KB
#include "gap.h"
#include <bits/stdc++.h>

#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 1;


pll query(ll x, ll y){
	pll p;
	//cout<<x<<" "<<y<<endl;
	MinMax(x, y, &p.first, &p.second);
	return p;
}

vector<pll> vt;

vector<ll> v;

long long findGap(int T, int N){
	if(T==1){
		int s = 0, e = 1e18;
		while(1){
			pll p = query(s, e);
			if(p.first==-1)	break;
			v.pb(p.first);
			if(p.first==p.second)	break;
			v.pb(p.second);
			s = p.first+1; e = p.second-1;
		}
		sort(v.begin(), v.end());
		ll a = 0;
		for(int i=0; i<v.size()-1; i++){
			a = max(a, v[i+1]-v[i]);
		}
		return a;
	}
	pll p1 = query(0, 1e18);
	if(N==2){
		return p1.second-p1.first;
	}
	ll s = p1.first, e = p1.second;
	if(e-s==2){
		return 1LL;
	}
	ll L = (e-s-2)/N;
	ll ans = L;
	vt.pb({s, s});
	ll n = s+1;
	for(int i=0; i<N; i++){
		if(n>=e)	break;
		pll p = query(n, min(n+L, e));
		if(p.first!=-1){
			vt.pb({p.first, p.second});
		}
		n+=L+1;
	}
	vt.pb({e, e});
	for(int i=0; i<vt.size()-1; i++){
		ans = max(ans, vt[i+1].first-vt[i].second);
	}
	return ans;
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:42:18: warning: overflow in implicit constant conversion [-Woverflow]
   int s = 0, e = 1e18;
                  ^~~~
gap.cpp:53:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0; i<v.size()-1; i++){
                ~^~~~~~~~~~~
gap.cpp:79:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<vt.size()-1; i++){
               ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 3 ms 248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 1 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Correct 2 ms 380 KB Output is correct
6 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 2 ms 376 KB Execution failed because the return code was nonzero
11 Runtime error 3 ms 520 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 3 ms 680 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Correct 1 ms 376 KB Output is correct
16 Runtime error 10 ms 892 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 9 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 10 ms 888 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 10 ms 888 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 12 ms 888 KB Execution failed because the return code was nonzero
21 Runtime error 30 ms 2040 KB Execution killed with signal 11 (could be triggered by violating memory limits)
22 Runtime error 31 ms 2168 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Runtime error 32 ms 2168 KB Execution killed with signal 11 (could be triggered by violating memory limits)
24 Runtime error 30 ms 2168 KB Execution killed with signal 11 (could be triggered by violating memory limits)
25 Correct 22 ms 1148 KB Output is correct
26 Runtime error 30 ms 2040 KB Execution killed with signal 11 (could be triggered by violating memory limits)
27 Runtime error 31 ms 2040 KB Execution killed with signal 11 (could be triggered by violating memory limits)
28 Runtime error 31 ms 2168 KB Execution killed with signal 11 (could be triggered by violating memory limits)
29 Runtime error 31 ms 2040 KB Execution killed with signal 11 (could be triggered by violating memory limits)
30 Runtime error 43 ms 2288 KB Execution failed because the return code was nonzero
31 Incorrect 2 ms 376 KB Output isn't correct
32 Incorrect 2 ms 376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 424 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 21 ms 888 KB Output is correct
17 Correct 20 ms 888 KB Output is correct
18 Correct 20 ms 1000 KB Output is correct
19 Correct 20 ms 888 KB Output is correct
20 Correct 11 ms 504 KB Output is correct
21 Correct 80 ms 2288 KB Output is correct
22 Correct 74 ms 2288 KB Output is correct
23 Correct 77 ms 2292 KB Output is correct
24 Correct 89 ms 2288 KB Output is correct
25 Correct 77 ms 3308 KB Output is correct
26 Correct 84 ms 2284 KB Output is correct
27 Correct 80 ms 2288 KB Output is correct
28 Correct 80 ms 2292 KB Output is correct
29 Correct 81 ms 2292 KB Output is correct
30 Correct 36 ms 1656 KB Output is correct
31 Correct 1 ms 252 KB Output is correct
32 Correct 2 ms 376 KB Output is correct