11332022-03-13 16:23:56ZsofiaKeresztelyFőzet készítéscpp11Time limit exceeded 0/50550ms47096 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	vector<vector<int> > relprim(500);
	relprim[1].push_back(1);
	for (int i=1; i<500; i++)
	{
		for (int j=1; j<i; j++)
		{
			if (__gcd(i, j)==1)
			{
				relprim[i].push_back(j);
				relprim[j].push_back(i);
			}
		}
	}
	vector<vector<vector<int> > > dp(501, vector<vector<int> >(501, vector<int>(35)));
	//a, b, i
	int ak, bk;
	for (int a=1; a<=500; a++)
	{
		for (int b=1; b<=500; b++)
		{
			for (int i=sqrt(2*a); i>0; i--)
			{
				ak=0; bk=0;
				for (int x : relprim[i])
				{
					ak+=i; bk+=x;
					if (a-ak<0||b-bk<0)
					{
						break;
					}
					else
					{
						dp[a][b][i]=max(dp[a][b][i], dp[a-ak][b-bk][i+1]+ak/i);
					}
				}
				/*
				a darab van összesen az elsőből
				b darab a másodikból
				dp[a][b][i] = hány darabot tudunk csinálni maximum, ha az elsőből mindig legalább i-t használunk
				*/
				
			}
		}
	}
	int t, a, b;
	cin>>t;
	for (int i=0; i<t; i++)
	{
		cin>>a>>b;
		cout<<dp[a][b][1]<<"\n";
	}
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Time limit exceeded0/0479ms47032 KiB
2Time limit exceeded0/0460ms46996 KiB
3Time limit exceeded0/3481ms47024 KiB
4Time limit exceeded0/2460ms47072 KiB
5Time limit exceeded0/3460ms46960 KiB
6Time limit exceeded0/2504ms46952 KiB
7Time limit exceeded0/3456ms47096 KiB
8Time limit exceeded0/2497ms46980 KiB
9Time limit exceeded0/3477ms46984 KiB
10Time limit exceeded0/2493ms46984 KiB
11Time limit exceeded0/2470ms47052 KiB
12Time limit exceeded0/2485ms46920 KiB
13Time limit exceeded0/2547ms46988 KiB
14Time limit exceeded0/2499ms46988 KiB
15Time limit exceeded0/2550ms46924 KiB
16Time limit exceeded0/2483ms46988 KiB
17Time limit exceeded0/2523ms46992 KiB
18Time limit exceeded0/2488ms46988 KiB
19Time limit exceeded0/2490ms46988 KiB
20Time limit exceeded0/3500ms46984 KiB
21Time limit exceeded0/3541ms46980 KiB
22Time limit exceeded0/3503ms46988 KiB
23Time limit exceeded0/3483ms47052 KiB