CSES - HIIT Open 2024 - Results
Submission details
Task:Equilateral numbers
Sender:ä
Submission time:2024-11-16 16:58:05 +0200
Language:C++ (C++17)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6--details
#7--details
#8--details
#9--details
#10ACCEPTED0.00 sdetails
#11--details
#12--details

Code

#include <bits/stdc++.h>

// g++ -std=c++17 e.cpp -o e
using namespace std;
unordered_map<int64_t, int> d;
int hae(int64_t n, int level){
    if (n==1) return 1;
    if (n==2) return 2;
    if (n==3) return 1;
    if (n==4) return 2;
    if (n==5) return 3;
    if (n==7) return 2;
    if (n==8) return 3;
    if (n==9) return 2;

    int64_t b = (-1+sqrt(1+8*n))/2-5;
    //cout << n <<  " " << b <<endl;
    //return 0;
    while((b*(b+1))/2 < n){
        b += 1;
    }
    while((b*(b+1))/2 > n){
        b -= 1;
    }
    if ((b*(b+1))/2 == n){
        return 1;
    }
    if (d.find(n) != d.end()) return d[n];
    
    if (level >= 2) return 100000;
    while((b*(b+1))/2 > n) {
        b--;
    }
    int mi = 100000;
    while(b > 0){
        int h = hae(n-(b*(b+1))/2, level+1);
        mi = min(mi, h);
        --b;
    }
    d[n] = mi+1;
    return mi+1;
}

int main() {
    int64_t n; cin >> n;
    
    //for (int64_t i = 1; i <= 28; ++i){
    //    cout << i << " " << hae(i) << endl;
    //}
    auto ans = hae(n, 0);
    if (ans >= 100000){
        cout << 3 << endl;
        return 0;
    }
    cout << ans << endl;
    return 0;
}

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:

input
12385719843

correct output
3

user output
(empty)

Test 7

Verdict:

input
10935032

correct output
3

user output
(empty)

Test 8

Verdict:

input
659023495928

correct output
3

user output
(empty)

Test 9

Verdict:

input
913591235689

correct output
2

user output
(empty)

Test 10

Verdict: ACCEPTED

input
999999911791

correct output
1

user output
1

Test 11

Verdict:

input
1000000000000

correct output
2

user output
(empty)

Test 12

Verdict:

input
999999999998

correct output
3

user output
(empty)