QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#96594#5591. Fading WindPetroTarnavskyi#RE 0ms0kbC++172.9kb2023-04-14 16:40:312023-04-14 16:40:34

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-14 16:40:34]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-04-14 16:40:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int N = 1 << 10;

vector<int> tubes[N];
set<int> poses[N][3];
vector<pair<int, int>> ans;

void moveBall(int i, int j) {
	int c = tubes[i].back();
	tubes[i].pop_back();
	poses[c][SZ(tubes[i])].erase(i);
	poses[c][SZ(tubes[j])].insert(j);
	tubes[j].push_back(c);
	ans.emplace_back(i, j);
	assert(SZ(tubes[j]) <= 3);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	FOR(i, 1, n + 2) {
		FOR(j, 0, 3) {
			int c;
			cin >> c;
			if (c != 0) {
				tubes[i].push_back(c);
				poses[c][j].insert(i);
			}
		}
	}
	int j = 1;
	FOR(i, 2, n + 2) {
		if (SZ(tubes[i]) < SZ(tubes[j])) {
			j = i;
		}
	}
	FOR(i, 1, n + 2) {
		if (i == j) {
			continue;
		}
		while (SZ(tubes[i]) < 3) {
			moveBall(j, i);
		}
	}
	FOR(c, 1, n + 1) {
		if (!poses[c][0].empty()) {
			continue;
		}
		int i, depth;
		if (!poses[c][2].empty()) {
			i = *poses[c][2].begin();
			depth = 0;
		}
		else {
			assert(!poses[c][1].empty());
			i = *poses[c][1].begin();
			depth = 1;
		}
		int k = -1;
		FOR(pos, 1, n + 2) {
			if (pos != i && pos != j && SZ(poses[tubes[pos][0]][0]) > 1) {
				k = pos;
			}
		}
		assert(k != -1);
		moveBall(k, j);
		if (depth) {
			moveBall(i, j);
		}
		moveBall(i, k);
		FOR(l, 0, depth + 1) {
			moveBall(j, i);
		}
		FOR(l, 0, 3) {
			moveBall(k, j);
		}
		j = k;
	}
	FOR(c, 1, n + 1) {
		int k = *poses[c][0].begin();
		if (tubes[k][1] == c) {
			continue;
		}
		int i, depth;
		if (!poses[c][2].empty()) {
			i = *poses[c][2].begin();
			depth = 0;
		}
		else {
			assert(!poses[c][1].empty());
			i = *poses[c][1].begin();
			depth = 1;
		}
		FOR(l, 0, 2) {
			moveBall(k, j);
		}
		FOR(l, 0, depth) {
			moveBall(i, j);
		}
		moveBall(i, k);
		moveBall(j, k);
		FOR(l, 0, depth + 1) {
			moveBall(j, i);
		}
	}
	FOR(i, 1, n + 2) {
		FOR(k, 0, SZ(tubes[i])) {
			assert(poses[tubes[i][k]][k].count(i));
		}
	}
	FOR(i, 1, n + 2) {
		for (int c : tubes[i]) {
			cerr << c << " ";
		}
		cerr << endl;
	}
	FOR(c, 1, n + 1) {
		int k = *poses[c][0].begin();
		assert(tubes[k][1] == c);
		if (tubes[k][2] == c) {
			continue;
		}
		int i = *poses[c][2].begin();
		moveBall(k, j);
		moveBall(i, k);
		moveBall(j, i);
	}
	FOR(i, 1, n + 2) {
		if (i == j) {
			assert(tubes[i].empty());
		}
		else {
			assert(SZ(tubes[j]) == 3 && tubes[0] == tubes[1] && tubes[0] == tubes[2]);
		}
	}
	cout << SZ(ans) << "\n";
	for (auto [u, v] : ans) {
		cout << u << " " << v << "\n";
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Dangerous Syscalls

input:

1 1 1 1

output:


result: