10932022-03-02 20:51:28peti1234Vizeskannákcpp14Wrong answer 7/40153ms14596 KiB
#include <bits/stdc++.h>

using namespace std;
int m1, m2, m3, l;
set<pair<int, int> > volt;
queue<pair<pair<int, int>, int> > q;
void pb(int a, int b, int db) {
    if (volt.find({a, b})==volt.end()) {
        volt.insert({a, b});
        q.push({{a, b}, db});
    }
}
int main()
{
    cin >> m1 >> m2 >> m3 >> l;
    pb(m1, 0, 0);
    while (q.size()>0) {
        int a=q.front().first.first, b=q.front().first.second, c=m1-a-b, db=q.front().second;
        q.pop();
        if (a==l || b==l || c==l) {
            cout << db << "\n";
            return 0;
        }
        db++;

        int kul=min(a, m2-b);
        pb(a-kul, b+kul, db);

        kul=min(m1-a, m2);
        pb(a+kul, b-kul, db);

        kul=min(a, m3-c);
        pb(a-kul, b, db);

        kul=min(m1-a, c);
        pb(a+kul, b, db);

        kul=min(b, m3-c);
        pb(a, b-kul, db);

        kul=min(m2-b, c);
        pb(a, b+kul, db);

    }
    cout << -1 << "\n";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base7/40
1Accepted0/02ms1812 KiB
2Wrong answer0/01ms1820 KiB
3Wrong answer0/11ms1852 KiB
4Wrong answer0/12ms1864 KiB
5Wrong answer0/11ms1864 KiB
6Accepted1/11ms1864 KiB
7Wrong answer0/11ms1872 KiB
8Wrong answer0/11ms1876 KiB
9Accepted1/11ms1876 KiB
10Accepted1/11ms1892 KiB
11Wrong answer0/11ms1888 KiB
12Wrong answer0/11ms1896 KiB
13Wrong answer0/21ms1908 KiB
14Accepted2/21ms1896 KiB
15Wrong answer0/21ms1904 KiB
16Wrong answer0/22ms1932 KiB
17Wrong answer0/21ms1912 KiB
18Wrong answer0/21ms1928 KiB
19Wrong answer0/21ms1920 KiB
20Wrong answer0/22ms1972 KiB
21Wrong answer0/21ms1928 KiB
22Accepted2/24ms2288 KiB
23Wrong answer0/213ms2860 KiB
24Wrong answer0/217ms3524 KiB
25Wrong answer0/28ms2996 KiB
26Wrong answer0/2105ms10668 KiB
27Wrong answer0/2153ms14596 KiB