Task: | Equilateral numbers |
Sender: | Vaicode |
Submission time: | 2024-11-16 16:44:28 +0200 |
Language: | C++ (C++20) |
Status: | READY |
Result: | WRONG ANSWER |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.42 s | details |
#2 | ACCEPTED | 0.42 s | details |
#3 | ACCEPTED | 0.42 s | details |
#4 | ACCEPTED | 0.42 s | details |
#5 | ACCEPTED | 0.42 s | details |
#6 | WRONG ANSWER | 0.47 s | details |
#7 | ACCEPTED | 0.41 s | details |
#8 | WRONG ANSWER | 0.93 s | details |
#9 | ACCEPTED | 0.94 s | details |
#10 | ACCEPTED | 0.95 s | details |
#11 | WRONG ANSWER | 0.98 s | details |
#12 | WRONG ANSWER | 1.00 s | details |
Code
#include<iostream> #include<vector> #include <cmath> #include <map> using namespace std; typedef long long ll; #define lim 301010 ll dp[lim]; map<ll, bool> ek; ll e(ll k){ return k*(k+1)/2; } int main() { ll m = 0; dp[0] = 0; for(ll i = 1; i< lim; ++i){ ek[e(i)] = 1; dp[i] = 1e18; for (ll j =0; e(j) <= i; j++) { dp[i] = min(dp[i-e(j)] + 1, dp[i]); } m = max(dp[i], m); } ll n; cin >> n; ll res = 100; for(ll i = 1; e(i) <= n; ++i){ if(e(i) == n){ cout << "1\n"; return 0; } if(ek[n - e(i)]){ cout << "2\n"; return 0; } if(n - e(i) < lim){ res = min(res, dp[n-e(i)]+1); } } cout << res << endl; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
1 |
correct output |
---|
1 |
user output |
---|
1 |
Test 2
Verdict: ACCEPTED
input |
---|
2 |
correct output |
---|
2 |
user output |
---|
2 |
Test 3
Verdict: ACCEPTED
input |
---|
3 |
correct output |
---|
1 |
user output |
---|
1 |
Test 4
Verdict: ACCEPTED
input |
---|
5 |
correct output |
---|
3 |
user output |
---|
3 |
Test 5
Verdict: ACCEPTED
input |
---|
33 |
correct output |
---|
3 |
user output |
---|
3 |
Test 6
Verdict: WRONG ANSWER
input |
---|
12385719843 |
correct output |
---|
3 |
user output |
---|
4 |
Test 7
Verdict: ACCEPTED
input |
---|
10935032 |
correct output |
---|
3 |
user output |
---|
3 |
Test 8
Verdict: WRONG ANSWER
input |
---|
659023495928 |
correct output |
---|
3 |
user output |
---|
100 |
Test 9
Verdict: ACCEPTED
input |
---|
913591235689 |
correct output |
---|
2 |
user output |
---|
2 |
Test 10
Verdict: ACCEPTED
input |
---|
999999911791 |
correct output |
---|
1 |
user output |
---|
1 |
Test 11
Verdict: WRONG ANSWER
input |
---|
1000000000000 |
correct output |
---|
2 |
user output |
---|
3 |
Test 12
Verdict: WRONG ANSWER
input |
---|
999999999998 |
correct output |
---|
3 |
user output |
---|
4 |