QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#41157#1646. Disk SortrinnechanWA 2ms3740kbC++4.0kb2022-07-28 11:44:442022-07-28 11:44:45

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-07-28 11:44:45]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3740kb
  • [2022-07-28 11:44:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define nl << '\n'
#define sp << ' '
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define ins insert
#define ii pair<int, int>
const int maxn = 1e3 + 69;
vector<int> arr[maxn];
vector<ii> locate[maxn];
int cnt = 0; vector<ii> res;

void swap(int i, int j) {
	cnt++; res.pb({i, j}); vector<ii> cur;
	int x = arr[i][arr[i].size() - 1];
	arr[i].pop_back(); arr[j].pb(x);
	while (!locate[x].empty()) {
		if (locate[x][locate[x].size() - 1].fi == arr[i].size() && locate[x][locate[x].size() - 1].se == i) {locate[x].pop_back(); cur.pb({3 - arr[j].size(), j});}
		else {cur.pb(locate[x][locate[x].size() - 1]); locate[x].pop_back();}
	} locate[x] = cur;
}

void solve() { int n; cin >> n;
    for (int i = 1; i <= 3; i++) {
        for (int j = 1; j <= n; j++) {
            int x; cin >> x; arr[i].pb(x);
            locate[x].pb({i, j});
        }
    }
    
    int empty = n + 1;
    for (int i = 1; i <= n; i++) {
    	for (int x = 1; x <= n; x++) {
    		if (locate[x][0].se == locate[x][1].se && locate[x][1].se == locate[x][0].se) continue;
    		sort(locate[x].begin(), locate[x].end()); bool anymove = false;
    		int a = locate[x][0].se, b = locate[x][1].se, c = locate[x][2].se;
    		if (locate[x][0].fi == 1 && locate[x][1].fi == 1 && locate[x][2].fi == 2) {
    			int a = locate[x][0].se, b = locate[x][1].se, c = locate[x][2].se;
    			swap(a, empty); swap(b, empty);
    			if (a == c) {
    				swap(c, empty);
    				swap(c, b);
				} else if (b == c) {
					swap(c, empty);
					swap(c, a);
				} else {
					swap(c, a);
					swap(c, empty);
					swap(c, b);
				} empty = c; 
				anymove = true;
			} else if (locate[x][0].fi == 1 && locate[x][1].fi == 2 && locate[x][2].fi == 2) {
				int a = locate[x][0].se, b = locate[x][1].se, c = locate[x][2].se;
				swap(a, empty);
				if (a == b) {
					swap(b, empty);
					swap(c, a);
					swap(c, empty);
					swap(c, a);
					empty = c;
				} else if (a == c) {
					swap(c, empty);
					swap(b, a);
					swap(b, empty);
					swap(b, a);
					empty = b;
				} else {
					swap(b, a);
					swap(b, empty);
					swap(c, b);
					swap(c, empty);
					swap(c, b);
					empty = c;
				} anymove = true;
			} else if (locate[x][0].fi == 1 && locate[x][1].fi == 2 && locate[x][2].fi == 3) {
				int a = locate[x][0].se, b = locate[x][1].se, c = locate[x][2].se;
				if (b == c) {
					swap(c, empty);
					swap(a, c);
					swap(empty, a);
				} else if (a == b) {
					swap(a, empty);
					swap(a, empty);
					swap(c, a);
					swap(c, a);
					swap(c, empty);
					empty = c;
				} else {
					swap(a, empty);
					swap(b, a);
					swap(b, empty);
					swap(c, b);
					swap(c, b);
					swap(c, empty);
					empty = c;
				} anymove = true;
			} else if (locate[x][0].fi == 1 && locate[x][1].fi == 1 && locate[x][2].fi == 1) {
				int a = locate[x][0].se, b = locate[x][1].se, c = locate[x][2].se;
				swap(a, empty); swap(b, empty); swap(c, empty);
				swap(a, b); swap(a, c); empty = a; anymove = true;
			} else if (locate[x][0].fi == 1 && locate[x][1].fi == 1 && locate[x][2].fi == 3) {
				int a = locate[x][0].se, b = locate[x][1].se, c = locate[x][2].se;
				if (a == c) {
					swap(a, empty);
					swap(b, empty);
					swap(a, b);
					swap(a, empty);
					empty = a;
				} else if (b == c) {
					swap(b, empty);
					swap(a, empty);
					swap(b, a);
					swap(b, empty);
					empty = b;
				} else {
					swap(c, empty);
					swap(c, empty);
					swap(a, c);
					swap(b, c);
					swap(empty, a);
					swap(empty, b);
				} anymove = true;
			} if (anymove) break;
		} 
	}
	
	if (empty != n + 1) {
		swap(n + 1, empty);
		swap(n + 1, empty);
		swap(n + 1, empty);
	}
	
	cout << cnt nl;
	for (int i = 0; i < cnt; i++) {
		cout << res[i].fi sp << res[i].se nl;
	}
}

signed main() {
	ios_base::sync_with_stdio(NULL);
    cin.tie(nullptr); cout.tie(nullptr);
    int t = 1; while (t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3684kb

input:

4
2 3 1 4
2 1 1 4
2 3 3 4

output:

8
3 5
3 5
2 3
2 5
2 3
5 2
5 2
5 2

result:

ok n=4

Test #2:

score: 0
Accepted
time: 2ms
memory: 3740kb

input:

2
1 2
1 2
1 2

output:

0

result:

ok n=2

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3632kb

input:

3
2 2 1
1 3 3
1 2 3

output:

18
1 4
3 1
4 3
3 4
4 3
4 4
1 4
1 4
1 4
3 1
4 3
4 1
1 4
1 4
1 1
4 1
4 1
4 1

result:

wrong answer Invalid move #5