33002023-02-24 17:36:43zsomborHanoi tornyai variáns (45)cpp17Wrong answer 4/45323ms6736 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].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, 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
base4/45
1Wrong answer0/03ms1872 KiB
2Wrong answer0/03ms2080 KiB
3Wrong answer0/23ms2312 KiB
4Accepted2/23ms2540 KiB
5Accepted2/23ms2748 KiB
6Wrong answer0/33ms2832 KiB
7Wrong answer0/23ms2836 KiB
8Wrong answer0/23ms3044 KiB
9Wrong answer0/24ms3064 KiB
10Wrong answer0/24ms3120 KiB
11Wrong answer0/24ms3212 KiB
12Wrong answer0/27ms3224 KiB
13Wrong answer0/218ms3492 KiB
14Wrong answer0/239ms3944 KiB
15Wrong answer0/254ms4696 KiB
16Time limit exceeded0/2323ms6736 KiB
17Wrong answer0/2123ms4960 KiB
18Wrong answer0/2178ms5844 KiB
19Wrong answer0/3185ms6360 KiB
20Wrong answer0/3184ms5996 KiB
21Wrong answer0/3186ms6416 KiB
22Wrong answer0/385ms5912 KiB