33012023-02-24 18:09:46zsomborHanoi tornyai variáns (45)cpp17Wrong answer 4/4597ms5212 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, hol(mx));
    ans1 = lep;

    for (int i = 1; i <= 3; i++) v[i].clear();
    lep.clear();
    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, hol(mx));
    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
base4/45
1Accepted0/03ms1872 KiB
2Wrong answer0/03ms2080 KiB
3Wrong answer0/23ms2288 KiB
4Wrong answer0/23ms2776 KiB
5Accepted2/23ms2604 KiB
6Wrong answer0/33ms2732 KiB
7Wrong answer0/23ms2672 KiB
8Wrong answer0/23ms2800 KiB
9Wrong answer0/23ms3040 KiB
10Wrong answer0/23ms2920 KiB
11Wrong answer0/23ms3164 KiB
12Wrong answer0/23ms3284 KiB
13Wrong answer0/217ms3716 KiB
14Accepted2/217ms4120 KiB
15Wrong answer0/226ms4100 KiB
16Wrong answer0/259ms4160 KiB
17Wrong answer0/250ms4504 KiB
18Wrong answer0/256ms4272 KiB
19Wrong answer0/397ms4940 KiB
20Wrong answer0/375ms5212 KiB
21Wrong answer0/328ms4344 KiB
22Wrong answer0/341ms4324 KiB