32992023-02-24 17:29:33zsomborHanoi tornyai variáns (45)cpp17Wrong answer 0/45363ms7672 KiB
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int a, mx = 0;
vector <vector <int>> v(4);
vector <pair <int, int>> lep;
vector <pair <int, int>> ans1;
vector <pair <int, int>> ans2;

int hol(int x) {
    for (int& i : v[1]) if (i == x) return 1;
    for (int& i : v[2]) if (i == x) return 2;
    for (int& i : v[3]) if (i == x) return 3;
    return 0;
}

void hanoi(int x, int ra) {
    if (!x) return;
    int rol = hol(x);
    if (rol != ra) {
        hanoi(x - 1, 6 / rol / ra);
        v[rol].pop_back();
        v[ra].push_back(x);
        lep.push_back({ rol,ra });
    }
    hanoi(x - 1, ra);
}

int main()
{
    while (cin >> a && a) { v[1].push_back(a); mx++; }
    while (cin >> a && a) { v[2].push_back(a); mx++; }
    while (cin >> a && a) { v[3].push_back(a); mx++; }
    hanoi(mx, 1);
    ans1 = lep;

    for (int i = 1; i <= 3; i++) v[i].resize(0);
    while (cin >> a && a) v[1].push_back(a);
    while (cin >> a && a) v[2].push_back(a);
    while (cin >> a && a) v[3].push_back(a);
    hanoi(mx, 1);
    ans2 = lep;
    
    cout << ans1.size() + ans2.size() << endl;
    for (auto p : ans1) cout << p.first << " " << p.second << endl;
    reverse(ans2.begin(), ans2.end());
    for (auto p : ans2) cout << p.second << " " << p.first << endl;
}
SubtaskSumTestVerdictTimeMemory
base0/45
1Wrong answer0/03ms1876 KiB
2Wrong answer0/03ms2116 KiB
3Wrong answer0/23ms2340 KiB
4Wrong answer0/23ms2496 KiB
5Wrong answer0/23ms2708 KiB
6Wrong answer0/33ms2952 KiB
7Wrong answer0/23ms3164 KiB
8Wrong answer0/23ms3236 KiB
9Wrong answer0/24ms3388 KiB
10Wrong answer0/24ms3464 KiB
11Wrong answer0/27ms3748 KiB
12Wrong answer0/28ms3828 KiB
13Wrong answer0/226ms4148 KiB
14Wrong answer0/294ms4808 KiB
15Wrong answer0/2192ms5536 KiB
16Time limit exceeded0/2363ms5548 KiB
17Wrong answer0/2231ms6396 KiB
18Wrong answer0/2223ms7456 KiB
19Time limit exceeded0/3363ms5328 KiB
20Wrong answer0/3229ms7672 KiB
21Wrong answer0/3209ms7492 KiB
22Wrong answer0/3172ms7476 KiB