Submission #1015295

# Submission time Handle Problem Language Result Execution time Memory
1015295 2024-07-06T08:29:12 Z vjudge1 Gap (APIO16_gap) C++17
0 / 100
32 ms 1268 KB
#include "gap.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long

bool adj(int x,int y)
{
	long long a, b;
	MinMax(x+1,y-1,&a,&b);
	return a==-1;
}

long long findGap(signed t,signed n)
{
	if (t==2 && n>60)
	{
		ll mn1,mx1;
		MinMax(0,(ll)1e18,&mn1,&mx1);
		ll st,mn,mx,ans=0;
		for (int i=0;i<=60;i++)
		{
			MinMax(mn1+1,mn1+(1LL<<i),&mn,&mx);
			if (mn!=-1)
			{
				ans=mn-mn1;
				st=mx;
				break;
			}
		}
		while (st<mx1)
		{
			MinMax(st+1,st+ans,&mn,&mx);
			if (mn!=-1)
				st=mx;
			else
			{
				ll val=ans*2;
				while (1)
				{
					MinMax(st+1,st+val,&mn,&mx);
					if (mn!=-1)
					{
						ans=mn-st;
						st=mx;
						break;
					}
					val*=2;
				}
			}
		}
		return ans;
	}
	else
	{
		long long lim1=0,lim2=1e18;
		long long mn,mx,mn1,mx1;
		MinMax(lim1,lim2,&mn1,&mx1);
		if (n==2)
			return mx1-mn1;
		MinMax(mn1+1,mx1-1,&mn,&mx);
		ll ans = max(mn-mn1,mx1-mx);
		while (mn+ans*2<=mx)
		{
			MinMax(mn+ans,mx-ans,&mn1,&mx1);
			if (mn1==-1)
				break;
			if (adj(mn,mn1))
				ans=mn1-mn;
			if (adj(mx1,mx))
				ans=max(ans,mx-mx1);
			mn=mn1,mx=mx1;
		}
		if (mn+ans<mx)
		{
			MinMax(mn+ans+1,mx,&mn1,&mx1);
			if (mn1!=-1)
				ans=mn1-mn;
			else
			{
				MinMax(mn,mx-ans-1,&mn1,&mx1);
				if (mx1!=-1)
					ans=mx-mx1;
			}
		}
		
		return ans;
	}
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:45:10: warning: 'st' may be used uninitialized in this function [-Wmaybe-uninitialized]
   45 |       ans=mn-st;
      |       ~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 0 ms 344 KB Execution failed because the return code was nonzero
3 Runtime error 0 ms 344 KB Execution failed because the return code was nonzero
4 Incorrect 0 ms 344 KB Output isn't correct
5 Incorrect 0 ms 344 KB Output isn't correct
6 Runtime error 0 ms 344 KB Execution failed because the return code was nonzero
7 Runtime error 0 ms 344 KB Execution failed because the return code was nonzero
8 Runtime error 0 ms 344 KB Execution failed because the return code was nonzero
9 Runtime error 0 ms 344 KB Execution failed because the return code was nonzero
10 Runtime error 0 ms 344 KB Execution failed because the return code was nonzero
11 Runtime error 1 ms 344 KB Execution failed because the return code was nonzero
12 Runtime error 0 ms 344 KB Execution failed because the return code was nonzero
13 Runtime error 0 ms 392 KB Execution failed because the return code was nonzero
14 Runtime error 0 ms 344 KB Execution failed because the return code was nonzero
15 Runtime error 0 ms 344 KB Execution failed because the return code was nonzero
16 Runtime error 3 ms 436 KB Execution failed because the return code was nonzero
17 Runtime error 4 ms 492 KB Execution failed because the return code was nonzero
18 Runtime error 4 ms 600 KB Execution failed because the return code was nonzero
19 Runtime error 5 ms 436 KB Execution failed because the return code was nonzero
20 Runtime error 2 ms 592 KB Execution failed because the return code was nonzero
21 Runtime error 12 ms 1112 KB Execution failed because the return code was nonzero
22 Runtime error 13 ms 1112 KB Execution failed because the return code was nonzero
23 Runtime error 12 ms 1208 KB Execution failed because the return code was nonzero
24 Runtime error 12 ms 1220 KB Execution failed because the return code was nonzero
25 Runtime error 10 ms 1112 KB Execution failed because the return code was nonzero
26 Runtime error 11 ms 1088 KB Execution failed because the return code was nonzero
27 Runtime error 15 ms 1192 KB Execution failed because the return code was nonzero
28 Runtime error 11 ms 1112 KB Execution failed because the return code was nonzero
29 Runtime error 21 ms 1268 KB Execution failed because the return code was nonzero
30 Runtime error 7 ms 1112 KB Execution failed because the return code was nonzero
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 0 ms 344 KB Execution failed because the return code was nonzero
3 Runtime error 0 ms 344 KB Execution failed because the return code was nonzero
4 Runtime error 0 ms 344 KB Execution failed because the return code was nonzero
5 Partially correct 0 ms 344 KB Partially correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Partially correct 1 ms 344 KB Partially correct
16 Correct 5 ms 440 KB Output is correct
17 Correct 7 ms 600 KB Output is correct
18 Correct 4 ms 600 KB Output is correct
19 Correct 4 ms 564 KB Output is correct
20 Correct 5 ms 600 KB Output is correct
21 Correct 16 ms 1208 KB Output is correct
22 Correct 28 ms 1112 KB Output is correct
23 Correct 16 ms 1112 KB Output is correct
24 Correct 16 ms 1112 KB Output is correct
25 Partially correct 32 ms 1112 KB Partially correct
26 Correct 17 ms 1084 KB Output is correct
27 Correct 17 ms 1112 KB Output is correct
28 Correct 27 ms 1112 KB Output is correct
29 Correct 27 ms 1112 KB Output is correct
30 Correct 15 ms 1112 KB Output is correct
31 Partially correct 0 ms 344 KB Partially correct
32 Correct 0 ms 344 KB Output is correct