11322022-03-13 16:20:52ZsofiaKeresztelyFőzet készítéscpp11Runtime error 0/50101ms125776 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>(501)));
	//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
1Runtime error0/090ms125636 KiB
2Runtime error0/079ms125732 KiB
3Runtime error0/378ms125688 KiB
4Runtime error0/282ms125680 KiB
5Runtime error0/379ms125688 KiB
6Runtime error0/279ms125684 KiB
7Runtime error0/390ms125680 KiB
8Runtime error0/282ms125776 KiB
9Runtime error0/3101ms125684 KiB
10Runtime error0/279ms125680 KiB
11Runtime error0/281ms125768 KiB
12Runtime error0/283ms125704 KiB
13Runtime error0/282ms125680 KiB
14Runtime error0/278ms125772 KiB
15Runtime error0/286ms125684 KiB
16Runtime error0/281ms125684 KiB
17Runtime error0/279ms125688 KiB
18Runtime error0/293ms125684 KiB
19Runtime error0/279ms125684 KiB
20Runtime error0/379ms125680 KiB
21Runtime error0/382ms125684 KiB
22Runtime error0/387ms125660 KiB
23Runtime error0/385ms125696 KiB