12452022-03-28 19:12:01ZsofiaKeresztelyFőzet készítéscpp11Accepted 50/50377ms4228 KiB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t, a, b;
  cin>>t;
  vector<vector<int> > dp(501, vector<int>(501, INT_MIN));
  vector<pair<int, int> > c;
  c.pb(mp(1, 1));
  for (int i=2; i<32; i++)
  {
    for (int j=1; j<=i; j++)
    {
      if (__gcd(i, j) == 1)
      {
        c.pb(mp(i, j));
        c.pb(mp(j, i));
      }
    }
  }
  dp[0][0]=0;
  for (auto x : c)
  {
    for (int a=500; a>=0; a--)
    {
      for (int b=500; b>=0; b--)
      {
        if (a>=x.first&&b>=x.second)
        {
          dp[a][b] = max(dp[a][b], dp[a-x.first][b-x.second]+1);
        }
      }
    }
  }
  for (int a=1; a<501; a++)
  {
    for (int b=1; b<501; b++)
    {
      dp[a][b] = max(dp[a][b], max(dp[a][b-1], dp[a-1][b]));
    }
  }
  for (int i=0; i<t; i++)
  {
    cin>>a>>b;
    cout<<dp[a][b]<<"\n";
  }
  return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/0367ms3856 KiB
2Accepted0/0377ms3936 KiB
3Accepted3/3363ms3920 KiB
4Accepted2/2370ms3924 KiB
5Accepted3/3361ms3936 KiB
6Accepted2/2372ms3940 KiB
7Accepted3/3363ms3972 KiB
8Accepted2/2347ms3980 KiB
9Accepted3/3347ms3988 KiB
10Accepted2/2354ms4012 KiB
11Accepted2/2365ms4020 KiB
12Accepted2/2358ms4036 KiB
13Accepted2/2344ms4056 KiB
14Accepted2/2349ms4076 KiB
15Accepted2/2352ms4096 KiB
16Accepted2/2344ms4100 KiB
17Accepted2/2340ms4116 KiB
18Accepted2/2338ms4132 KiB
19Accepted2/2372ms4148 KiB
20Accepted3/3368ms4172 KiB
21Accepted3/3365ms4188 KiB
22Accepted3/3361ms4200 KiB
23Accepted3/3375ms4228 KiB