Please read the new rule regarding the restriction on the use of AI tools. ×

JUDASS's blog

By JUDASS, history, 17 months ago, In English

This is problem link https://cses.fi/problemset/result/5982212/

include <bits/stdc++.h>

using namespace std; const int N=511; vector<vector> dp(N, vector(N, -1));

int find(int a, int b){ if(a == b) return 0; if(dp[a][b] != -1) return dp[a][b]; int A=1e9, B= 1e9; for(int x=1; x<a; ++x) { A=min(A, find(x,b)+find(a-x, b)+1); } for(int y=1; y<b; ++y) { B=min(B, find(a,y)+find(a,b-y)+1); } return dp[a][b]=min(A, B); } int main() { int a, b; cin>>a>>b; cout<<find(a, b);

return 0;

} My code is getting TLE in two cases while it's is under 10^4 iteration

Full text and comments »

  • Vote: I like it
  • -6
  • Vote: I do not like it