/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 363ms 2.109 MiB
#2 Accepted 364ms 2.066 MiB
#3 Accepted 371ms 2.07 MiB
#4 Accepted 412ms 2.223 MiB
#5 Accepted 465ms 2.074 MiB

Code

#include<bits/stdc++.h>
using namespace std;
const long long M=2e5+1,MOD=1000000007;
typedef long long ll;
int dp[M];
void precalculate(){
    dp[0]=1;
    for(int i=1;i<M;i++)dp[i]=MOD;
    for(int i=1;i*i<=2e5;i++){
        vector<int>temp(M,MOD);
        int l=i*i;
        for(int j=l;j<M;j++){
            
             if(dp[j-l]!=MOD && dp[j-l]){
                temp[j]=min(temp[j],dp[j-l]+1);
             }
             temp[j]=min(dp[j],temp[j]);
        }
        for(int j=l;j<M;j++)dp[j]=min(dp[j],temp[j]);
    }
 for(int i=1;i<=2e5;i++)if(dp[i]==MOD)dp[i]=0;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    precalculate();
    cin>>t;
    while(t--){
    int x;
    cin>>x;
    cout<<dp[x]-1<<"\n";

    
      
     
    }




    
   
   return 0;
 
}

Information

Submit By
Type
Submission
Problem
P1051 Square Sum
Language
C++20 (G++ 13.2.0)
Submit At
2024-04-22 08:51:33
Judged At
2024-11-11 03:36:18
Judged By
Score
100
Total Time
465ms
Peak Memory
2.223 MiB