12442022-03-28 19:00:19ZsofiaKeresztelyFőzet készítéscpp11Time limit exceeded 0/50532ms2400 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<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/0465ms1920 KiB
2Time limit exceeded0/0470ms1972 KiB
3Time limit exceeded0/3465ms2168 KiB
4Time limit exceeded0/2463ms2048 KiB
5Time limit exceeded0/3476ms1988 KiB
6Time limit exceeded0/2515ms2124 KiB
7Time limit exceeded0/3497ms2060 KiB
8Time limit exceeded0/2460ms2092 KiB
9Time limit exceeded0/3453ms2044 KiB
10Time limit exceeded0/2469ms2044 KiB
11Time limit exceeded0/2462ms2068 KiB
12Time limit exceeded0/2458ms2156 KiB
13Time limit exceeded0/2456ms2164 KiB
14Time limit exceeded0/2463ms2156 KiB
15Time limit exceeded0/2467ms2200 KiB
16Time limit exceeded0/2465ms2188 KiB
17Time limit exceeded0/2495ms2200 KiB
18Time limit exceeded0/2476ms2152 KiB
19Time limit exceeded0/2481ms2300 KiB
20Time limit exceeded0/3532ms2248 KiB
21Time limit exceeded0/3483ms2400 KiB
22Time limit exceeded0/3485ms2284 KiB
23Time limit exceeded0/3485ms2236 KiB