CSES - Aalto Competitive Programming 2024 - wk5 - Wed - Results
Submission details
Task:Program
Sender:aalto2024f_002
Submission time:2024-10-02 17:51:26 +0300
Language:C++ (C++20)
Status:COMPILE ERROR

Compiler report

cc1plus: error: '::main' must return 'int'

Code

#include <bits/stdc++.h>
#define int long long

using namespace std;
 
int cost(int current, map<int, int> &next) {
 
    if (current <= 0)
        return INT_MAX;
 
    if (current == 1)
        return 0;
 
    if (current == 4) {
        next[4] = 1;
        return 1;
    }
 
    if (current == 7) {
        next[7] = 4;
        next[4] = 1;
        return 2;
    }
 
    if (current % 2 == 0) {
        int rec = cost(current/2, next);
        if (rec == INT_MAX)
            return rec;
    
        next[current] = current/2;
        return rec+1;
    }
 
    else {
        int rec = cost((current-3)/2, next);
        next[current] = current-3;
        next[current-3] = (current-3)/2;
        if (rec == INT_MAX)
            return rec;
        return rec + 2;
    }
 
}
 
int main() {
 
    int target;
    cin >> target;
 
    map<int, int> next;
 
    int steps = cost(target, next);
 
    if (steps == INT_MAX) {
        cout << 0 << endl;
        return 0;
    }
 
    steps += 1;
 
    cout << steps << endl;
 
    vector<string> outputs;
 
    int current = target;
    while (current != 1) {
        int m = next[current];
        if (abs(m - current) == 3) {
            outputs.push_back("ADD");
        }
        else {
            outputs.push_back("MUL");
        }
        current = m;
    }
 
    for (int i = (int) outputs.size()-1; i >= 0; i--) {
        cout << outputs[i] << endl;
    }
 
    cout << "END" << endl;
    return 0;
 
}