32282023-02-22 22:01:56zsomborVizeskannákcpp17Accepted 40/4017ms6636 KiB
#include <iostream>
#include <vector>
#include <queue>
#include <set>
using namespace std;

struct str {
    int aa, bb, cc, ddis;
};

int A, B, C, L, a = 0, b = 0, c = 0, dis = 0, at;
queue <str> q;
set <pair <pair <int, int>, int>> s;

void add() {
    if (s.count({ {a,b},c })) return;
    if (a == L || b == L || c == L) { cout << dis; exit(0); }
    s.insert({ {a,b},c });
    str st; st.aa = a; st.bb = b; st.cc = c; st.ddis = dis;
    q.push(st);
}

void ont() {
    dis++;

    at = min(a, B - b);
    a -= at; b += at;
    add();
    a += at; b -= at;

    at = min(a, C - c);
    a -= at; c += at;
    add();
    a += at; c -= at;

    at = min(b, A - a);
    b -= at; a += at;
    add();
    b += at; a -= at;

    at = min(b, C - c);
    b -= at; c += at;
    add();
    b += at; c -= at;

    at = min(c, A - a);
    c -= at; a += at;
    add();
    c += at; a -= at;

    at = min(c, B - b);
    c -= at; b += at;
    add();
    c += at; b -= at;
}

int main()
{
    cin >> A >> B >> C >> L;
    a = A; add();
    while (q.size()) {
        str st = q.front(); q.pop();
        a = st.aa; b = st.bb; c = st.cc; dis = st.ddis;
        ont();
    }
    cout << -1;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1684 KiB
2Accepted0/03ms1992 KiB
3Accepted1/13ms2076 KiB
4Accepted1/13ms2304 KiB
5Accepted1/13ms2512 KiB
6Accepted1/13ms2712 KiB
7Accepted1/13ms2836 KiB
8Accepted1/13ms2912 KiB
9Accepted1/13ms3168 KiB
10Accepted1/13ms3384 KiB
11Accepted1/13ms3516 KiB
12Accepted1/13ms3684 KiB
13Accepted2/22ms3772 KiB
14Accepted2/23ms3764 KiB
15Accepted2/22ms3852 KiB
16Accepted2/22ms3864 KiB
17Accepted2/22ms3868 KiB
18Accepted2/23ms3868 KiB
19Accepted2/23ms3988 KiB
20Accepted2/23ms4360 KiB
21Accepted2/23ms4268 KiB
22Accepted2/22ms4264 KiB
23Accepted2/23ms4292 KiB
24Accepted2/210ms5644 KiB
25Accepted2/28ms5308 KiB
26Accepted2/217ms6636 KiB
27Accepted2/213ms6256 KiB