12432022-03-28 18:50:46ZsofiaKeresztelyFőzet készítéscpp11Time limit exceeded 0/50527ms2440 KiB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair

int main(){
  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<2*sqrt(500); 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
base0/50
1Time limit exceeded0/0467ms1840 KiB
2Time limit exceeded0/0472ms1960 KiB
3Time limit exceeded0/3477ms1960 KiB
4Time limit exceeded0/2493ms2028 KiB
5Time limit exceeded0/3495ms2036 KiB
6Time limit exceeded0/2492ms2040 KiB
7Time limit exceeded0/3495ms2044 KiB
8Time limit exceeded0/2467ms2060 KiB
9Time limit exceeded0/3455ms2072 KiB
10Time limit exceeded0/2456ms2032 KiB
11Time limit exceeded0/2495ms2044 KiB
12Time limit exceeded0/2495ms2120 KiB
13Time limit exceeded0/2493ms2072 KiB
14Time limit exceeded0/2497ms2152 KiB
15Time limit exceeded0/2493ms2236 KiB
16Time limit exceeded0/2527ms2124 KiB
17Time limit exceeded0/2495ms2200 KiB
18Time limit exceeded0/2497ms2220 KiB
19Time limit exceeded0/2451ms2236 KiB
20Time limit exceeded0/3469ms2196 KiB
21Time limit exceeded0/3463ms2348 KiB
22Time limit exceeded0/3456ms2232 KiB
23Time limit exceeded0/3456ms2440 KiB