Submission #1347147


Source Code Expand

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <functional>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#define MOD 1000000007
#define INF 1000000000000000000LL
#define MX 200

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;

ll A[MX],B[MX];
vector <P> gt[MX];
int sz;

void init()
{
	sz=0;
	A[sz]=1,B[sz]=0;
	sz++;
	A[sz]=2,B[sz]=1;
	sz++;
	while(1)
	{
		A[sz]=A[sz-1]+B[sz-1];
		B[sz]=A[sz-1];
		if(A[sz]>INF) break;
		sz++;
	}
	vector <P> vx;
	for(int i=0;i<sz;i++)
	{
		if(i==0)
		{
			vx.push_back(P(1,0));
			vx.push_back(P(2,0));
		}
		else if(i==1) 
		{
			vx.clear();
			vx.push_back(P(2,1));
			vx.push_back(P(3,1));
		}
		else
		{
			vector <P> nxt;
			for(int j=0;j<vx.size();j++)
			{
				P p=vx[j];
				ll a=p.second,b=p.first;
				for(int t=1;t<=2;t++)
				{
					a+=b;
					if(a>INF) break;
					if(i+1<sz&&a>=A[i+1]&&b>=B[i+1]) break;
					nxt.push_back(P(a,b));
				}
			}
			vx=nxt;
		}
		gt[i]=vx;
	}
}
P solve(ll X,ll Y)
{
	int mx=0;
	while(mx<sz)
	{
		if(A[mx]>X||B[mx]>Y) break;
		mx++;
	}
	if(mx==1)
	{
		return P(1,1);
	}
	ll ret=0;
	for(int i=0;i<gt[mx-2].size();i++)
	{
		P p=gt[mx-2][i];
		ll a=p.first,b=p.second;
		//printf("%lld %lld : %lld %lld\n",X,Y,a,b);
		swap(a,b);
		if(a<=X&&b<=Y)
		{
			ll nm=(X-a)/b;
			ret+=nm;
			ret%=MOD;
		}
	}
	return P(mx-1,ret);
}
int main()
{
	init();
	int Q;
	scanf("%d",&Q);
	while(Q--)
	{
		ll X,Y;
		scanf("%lld %lld",&X,&Y);
		P p=solve(X,Y);
		P q=solve(Y,X);
		if(p.first!=q.first) p=max(p,q);
		else
		{
			p.second+=q.second;
			if(p.second>=MOD) p.second-=MOD;
			//被るのは(x,x)の組、つまり、(1,1),(2,2)だけ
			if(p.first==1)
			{
				p.second--;
				if(X>=2&&Y>=2) p.second--;
				if(p.second<0) p.second+=MOD;
			}
		}
		printf("%lld %lld\n",p.first,p.second);
	}
	return 0;
}

Submission Info

Submission Time
Task F - Kenus the Ancient Greek
User yutaka1999
Language C++14 (GCC 5.4.1)
Score 1700
Code Size 2015 Byte
Status AC
Exec Time 921 ms
Memory 4096 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:104:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&Q);
                ^
./Main.cpp:108:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld",&X,&Y);
                           ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1700 / 1700
Status
AC × 2
AC × 26
Set Name Test Cases
Sample s1.txt, s2.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
01.txt AC 429 ms 3452 KB
02.txt AC 428 ms 3328 KB
03.txt AC 428 ms 3328 KB
04.txt AC 428 ms 3328 KB
05.txt AC 429 ms 3328 KB
06.txt AC 427 ms 3328 KB
07.txt AC 429 ms 3328 KB
08.txt AC 428 ms 3328 KB
09.txt AC 427 ms 3328 KB
10.txt AC 429 ms 3328 KB
11.txt AC 920 ms 2048 KB
12.txt AC 921 ms 2048 KB
13.txt AC 268 ms 1920 KB
14.txt AC 268 ms 1920 KB
15.txt AC 298 ms 4096 KB
16.txt AC 299 ms 4096 KB
17.txt AC 135 ms 3840 KB
18.txt AC 135 ms 3840 KB
19.txt AC 733 ms 3584 KB
20.txt AC 734 ms 3584 KB
21.txt AC 1 ms 384 KB
22.txt AC 1 ms 384 KB
23.txt AC 1 ms 384 KB
24.txt AC 1 ms 384 KB
s1.txt AC 1 ms 384 KB
s2.txt AC 1 ms 384 KB