33052023-02-24 18:53:20zsomborHanoi tornyai variáns (45)cpp17Wrong answer 4/45282ms7192 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/03ms2112 KiB
3Wrong answer0/23ms2332 KiB
4Accepted2/23ms2544 KiB
5Accepted2/23ms2756 KiB
6Wrong answer0/33ms2968 KiB
7Wrong answer0/23ms3176 KiB
8Wrong answer0/23ms3364 KiB
9Wrong answer0/24ms3604 KiB
10Wrong answer0/23ms3524 KiB
11Wrong answer0/26ms3648 KiB
12Wrong answer0/24ms3744 KiB
13Wrong answer0/237ms4428 KiB
14Wrong answer0/243ms4768 KiB
15Wrong answer0/286ms5160 KiB
16Wrong answer0/2282ms7192 KiB
17Wrong answer0/2127ms5600 KiB
18Wrong answer0/2167ms6380 KiB
19Wrong answer0/3123ms6752 KiB
20Wrong answer0/3104ms6592 KiB
21Wrong answer0/3193ms6948 KiB
22Wrong answer0/3150ms6392 KiB