Accepted
Code
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
cin.tie(0) -> sync_with_stdio(0);
const int N = 2e5 + 1, INF = 1e9;
vector<int> dp(N, INF);
dp[0] = 0;
for (int i = 1; i * i <= N; i++) {
for (int j = N - 1; j >= 1; --j) {
if (j >= i * i) {
dp[j] = min(dp[j], dp[j - i * i] + 1);
}
}
}
int tt;
cin >> tt;
while (tt--) {
int n;
cin >> n;
cout << (dp[n] == INF ? -1 : dp[n]) << "\n";
}
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1051 Square Sum
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2025-06-20 14:46:07
- Judged At
- 2025-06-20 14:46:07
- Judged By
- Score
- 100
- Total Time
- 140ms
- Peak Memory
- 1.469 MiB