QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#127563 | #5583. Color Tubes | batrr# | WA | 1ms | 3456kb | C++17 | 4.7kb | 2023-07-19 19:50:17 | 2023-07-19 19:50:30 |
Judging History
answer
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
const int N = 300500, inf = 1e9, mod = 998244353;
const ll INF = 1e18;
int sum(int a, int b) {
a += b;
if (a >= mod)
a -= mod;
return a;
}
int sub(int a, int b) {
a -= b;
if (a < 0)
a += mod;
return a;
}
int mult(int a, int b) {
return 1ll * a * b % mod;
}
int bp(int a, int b) {
int res = 1;
while (b) {
if (b & 1)
res = mult(res, a);
a = mult(a, a);
b >>= 1;
}
return res;
}
int inv(int x) {
return bp(x, mod - 2);
}
int n, a[N][3];
vector<pii> ans;
void op(int x, int y) {
// cerr << x << " " << y << endl;
// for (int i = 1; i <= n + 1; i++)
// cerr << a[i][0] << a[i][1] << a[i][2] << endl;
int xx = 2, yy = 2;
while (xx >= 0 && a[x][xx] == 0)
xx--;
while (yy >= 0 && a[y][yy] == 0)
yy--;
yy++;
if (xx == -1 || yy == 3)
assert(0);
a[y][yy] = a[x][xx];
a[x][xx] = 0;
ans.pb({x, y});
}
void solve() {
cin >> n;
for (int i = 1; i <= n + 1; i++)
for (int j = 0; j < 3; j++)
cin >> a[i][j];
while (a[n + 1][0] != 0) {
for (int i = 1; i <= n; i++) {
if (a[i][2] == 0) {
op(n + 1, i);
break;
}
}
}
for (int i = 1; i <= n; i++) {
if (a[i][0] == 0) {
op(i + 1, i);
op(i + 1, i);
op(i + 1, i);
}
int c = a[i][0];
if (a[i][1] != c) {
bool found = false;
int emp = -1;
for (int j = i + 1; j <= n + 1; j++)
if (a[j][0] == 0)
emp = j;
for (int j = i + 1; j <= n + 1 && !found; j++) {
for (int q = 0; q < 3 && !found; q++) {
if (a[j][q] == c) {
found = true;
if (q == 0) {
op(j, emp);
op(j, emp);
op(j, emp);
op(i, j);
op(i, j);
op(emp, i);
op(emp, i);
op(emp, j);
}
if (q == 1) {
op(j, emp);
op(j, emp);
op(i, j);
op(i, j);
op(emp, i);
op(emp, i);
}
if (q == 2) {
op(i, emp);
op(i, emp);
op(j, emp);
op(j, i);
op(emp, i);
op(emp, j);
op(emp, j);
}
}
}
}
}
if (a[i][2] != c) {
bool found = false;
int emp = -1;
for (int j = i + 1; j <= n + 1; j++)
if (a[j][0] == 0)
emp = j;
for (int j = i + 1; j <= n + 1 && !found; j++) {
for (int q = 0; q < 3 && !found; q++) {
if (a[j][q] == c) {
found = true;
if (q == 0) {
op(j, emp);
op(j, emp);
op(i, emp);
op(j, i);
}
if (q == 1) {
op(j, emp);
op(j, emp);
op(i, j);
op(emp, i);
op(emp, j);
}
if (q == 2) {
op(i, emp);
op(j, i);
op(emp, j);
}
}
}
}
}
}
// cerr << ans.size() << " " << n << endl;
cout << ans.size() << endl;
for (auto it: ans)
cout << it.f << " " << it.s << endl;
}
int main() {
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
// cout << "Case #" << i << endl;
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3452kb
input:
3 2 2 0 1 3 1 3 1 2 3 0 0
output:
15 4 1 1 4 3 1 4 3 3 4 3 4 2 3 2 3 4 2 4 2 3 4 3 4 2 3 4 2 4 3
result:
ok correct
Test #2:
score: 0
Accepted
time: 1ms
memory: 3456kb
input:
1 0 0 0 1 1 1
output:
3 2 1 2 1 2 1
result:
ok correct
Test #3:
score: 0
Accepted
time: 1ms
memory: 3448kb
input:
2 2 1 0 2 1 0 2 1 0
output:
13 3 1 3 2 2 3 2 3 2 3 1 2 1 2 3 1 3 1 3 2 1 3 2 1 3 2
result:
ok correct
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 3444kb
input:
3 0 0 0 1 2 3 1 2 3 1 2 3
output:
25 4 1 4 1 4 1 1 4 1 4 2 4 2 1 4 1 4 2 4 2 3 4 3 4 3 4 2 3 2 3 4 2 4 2 4 3 3 4 3 4 2 4 3 2 4 3 4 3 4 3
result:
wrong answer Mixed colors in tube 1.