QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#355977 | #6432. Puzzle in Inazuma | PorNPtree | WA | 1ms | 3948kb | C++14 | 5.5kb | 2024-03-17 14:22:52 | 2024-03-17 14:22:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, a[N][N];
vector< pair< pair< pair<int, int>, pair<int, int> >, int> > res;
void input()
{
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
for (int j = i + 1; j <= n; ++j) {
scanf("%d", &a[i][j]);
}
}
int s = 0;
for (int i = 1; i <= n; ++i) {
for (int j = i + 1; j <= n; ++j) {
int x;
scanf("%d", &x);
a[i][j] = x - a[i][j];
a[j][i] = a[i][j];
s += a[i][j];
}
}
if (s) {
puts("-1");
exit(0);
}
return;
}
void add(int a, int b, int c, int d, int e)
{
res.push_back({{{a, b}, {c, d}}, e});
e = -e;
::a[a][b] += e, ::a[a][c] += e, ::a[a][d] += e;
::a[b][c] -= e, ::a[b][d] -= e, ::a[c][d] -= e;
::a[b][a] += e, ::a[c][a] += e, ::a[d][a] += e;
::a[c][b] -= e, ::a[d][b] -= e, ::a[d][c] -= e;
return;
}
void tmodify(int a, int b, int c, int d, int e, int v)
{
add(d, a, b, e, v);
add(d, a, b, c, -v);
add(e, a, c, d, -v);
add(e, a, b, c, v);
return;
}
void modify(int a, int b, int c, int d, int e, int f, int v)
{
tmodify(a, b, c, d, e, v);
tmodify(a, b, c, f, e, -v);
return;
}
void modify(int a, int d, int f, int v)
{
int b = 0, c = 0, e = 0;
for (int i = 1; i <= n; ++i) {
if (i != a && i != d && i != f) {
if (!b) {
b = i;
} else if (!c) {
c = i;
} else if (!e) {
e = i;
}
}
}
if (n == 5) {
e = c, c = b, b = f;
assert(!(v & 1));
v = -v / 2;
tmodify(a, b, c, d, e, v);
tmodify(a, b, e, d, c, v);
return;
}
modify(a, b, c, d, e, f, v);
return;
}
void print()
{
printf("%d\n", (int)res.size());
for (int i = 0; i < (int)res.size(); ++i) {
printf("%d %d %d %d %d\n", res[i].first.first.first, res[i].first.first.second, res[i].first.second.first, res[i].first.second.second, res[i].second);
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
printf("%d %d: %d\n", i, j, a[i][j]);
assert(!a[i][j]);
}
}
return;
}
int b[N][N];
signed main()
{
input();
if (n >= 6) {
for (int i = 1; i <= n; ++i) {
for (int j = i + 1; j <= n; ++j) {
if (a[i][j]) {
int z = -1;
for (int k = i + 1; k <= n; ++k) {
if (k != i && k != j) {
z = k;
break;
}
}
modify(j, i, z, a[i][j]);
}
}
}
print();
} else if (n == 5) {
for (int z = 0; z < 1024; ++z) {
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
b[i][j] = a[i][j];
}
}
res.clear();
int C = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
if (j != i) {
int ta = 0, tb = 0, tc = 0;
for (int k = 1; k <= n; ++k) {
if (k != i && k != j) {
if (!ta) {
ta = k;
} else if (!tb) {
tb = k;
} else if (!tc) {
tc = k;
}
}
}
add(i, ta, tb, tc, (z >> (C++)) & 1);
}
}
}
int flag = 1;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
flag &= !(a[i][j] & 1);
}
}
if (!flag) {
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
a[i][j] = b[i][j];
}
}
continue;
}
for (int i = 1; i <= n; ++i) {
for (int j = i + 1; j <= n; ++j) {
if (a[i][j]) {
int z = -1;
for (int k = i + 1; k <= n; ++k) {
if (k != i && k != j) {
z = k;
break;
}
}
modify(j, i, z, a[i][j]);
}
}
}
print();
}
puts("-1");
} else {
if (a[1][2] + a[3][4] || a[1][3] + a[2][4] || a[1][4] + a[2][3]) {
puts("-1");
} else {
if (((a[1][2] + a[1][3]) & 1) || ((a[1][2] + a[1][4]) & 1) || ((a[1][3] + a[1][4]) & 1)) {
puts("-1");
} else {
add(2, 1, 3, 4, -(a[1][3] + a[1][4]) / 2);
add(3, 1, 2, 4, -(a[1][2] + a[1][4]) / 2);
add(4, 1, 2, 3, -(a[1][2] + a[1][3]) / 2);
print();
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3948kb
input:
4 0 1 1 0 0 1 1 0 0 1 1 0
output:
3 2 1 3 4 1 3 1 2 4 0 4 1 2 3 0 1 1: 0 1 2: 0 1 3: 0 1 4: 0 2 1: 0 2 2: 0 2 3: 0 2 4: 0 3 1: 0 3 2: 0 3 3: 0 3 4: 0 4 1: 0 4 2: 0 4 3: 0 4 4: 0
result:
wrong output format Extra information in the output file