QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#789879 | #9802. Light Up the Grid | MYdinosaur | WA | 41ms | 3664kb | C++14 | 3.4kb | 2024-11-27 22:24:55 | 2024-11-27 22:24:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pa;
int cost[5];
ll a[20];
ll f[20][20];
int p1[5] = {0, 1, 2, 4, 8};
int p2[3] = {0, 3, 12};
int p3[3] = {0, 5, 10};
int p4[2] = {0, 15};
struct node{
int x, y, z;
}b[1001];
int fa[20];
inline void read(int &x)
{
x = 0;
int w = 1; char c = getchar();
while (!isdigit(c)) {if (c == '-') w = -1; c = getchar();}
while (isdigit(c)) {x = x * 10 + (c ^ 48); c = getchar();}
x = x * w;
}
bool cmp(node f1, node f2)
{
return f1.z < f2.z;
}
int find(int x)
{
if (x == fa[x]) return x;
return fa[x] = find(fa[x]);
}
int main()
{
memset(f, 0x3f3f3f, sizeof(f));
int T;
read(T);
int h = 1e7 + 10;
for (int i = 1; i <= 4; i++)
{
read(cost[i]);
h = min(h, cost[i]);
}
for (int i = 0; i <= 15; i++)
{
f[i][i] = 0;
for (int j = 1; j <= 4; j++)
{
int x = i ^ p1[j];
f[i][x] = cost[1];
}
for (int j = 1; j <= 2; j++)
{
int x = i ^ p2[j];
f[i][x] = cost[2];
}
for (int j = 1; j <= 2; j++)
{
int x = i ^ p3[j];
f[i][x] = cost[3];
}
int x = i ^ 15;
f[i][x] = cost[4];
}
for (int k = 0; k <= 15; k++)
{
for (int i = 0; i <= 15; i++)
{
for (int j = 0; j <= 15; j++)
{
f[i][j] = min(f[i][k] + f[k][j], f[i][j]);
}
}
}
f[15][15] = 2 * h;
// cout << T << " " << f[15][15] << endl;
while (T > 0)
{
T--;
int m;
int tot = 0;
read(m);
int p = 0;
// cout << m << endl;
for (int k = 1; k <= m; k++)
{
ll t = 1;
a[k] = 0;
for (int i = 1; i <= 2; i++)
{
for (int j = 1; j <= 2; j++)
{
char ch;
cin >> ch;
if (ch == '1') a[k] += t;
t = t * 2;
}
}
if (a[k] == 15) p = 1;
}
fa[15] = 15;
for (int i = 1; i <= m; i++)
{
fa[a[i]] = a[i];
for (int j = 1; j <= m; j++)
{
if (i == j) continue;
tot++; b[tot].x = a[i]; b[tot].y = a[j]; b[tot].z = f[a[i]][a[j]];
// cout << tot << " " << a[i] << " " << a[j] <<" " << f[a[i]][a[j]]<< endl;
}
if (p == 0)
{
tot++;
b[tot].x = a[i];
b[tot].y = 15;
b[tot].z = f[a[i]][15];
// cout << " " << a[i] << " " << 15 << " " << f[a[i]][15] << endl;
}
}
if (p == 0)
{
m++;
}
sort(b + 1, b + tot + 1, cmp);
ll sum = 0;
for (int i = 1; i <= tot; i++)
{
int fx = find(b[i].x);
int fy = find(b[i].y);
// cout << b[i].x << " " << b[i].y << " " << fx << " " << fy << " " << b[i].z << endl;
if (fx == fy) continue;
sum += b[i].z;
fa[fx] = fy;
}
if (m == 1) sum = f[a[1]][15];
cout << sum << endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3580kb
input:
2 1000 100 10 1 4 10 00 01 00 00 10 00 01 1 11 11
output:
1121 2
result:
ok 2 number(s): "1121 2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
2 1 1 1 1 4 10 00 01 00 00 10 00 01 1 11 11
output:
5 2
result:
ok 2 number(s): "5 2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 41ms
memory: 3612kb
input:
10000 8 2 7 8 8 00 01 00 11 00 10 11 11 10 10 01 10 01 00 10 11 8 11 01 11 00 01 10 11 11 00 01 01 01 01 00 11 10 9 00 00 01 01 10 11 00 01 11 10 11 00 11 11 00 11 01 10 9 11 11 10 00 11 00 11 01 00 10 01 11 00 01 01 01 10 01 11 00 01 01 01 10 10 00 11 11 11 11 10 ...
output:
32 30 34 34 36 36 40 36 38 36 34 42 34 34 36 30 29 34 36 38 34 36 40 34 25 32 34 36 32 31 32 36 32 34 36 38 38 34 36 32 29 34 34 36 38 34 35 34 38 34 36 29 36 38 36 36 42 36 40 30 39 38 32 30 34 36 32 34 40 36 32 30 27 34 32 36 34 38 34 36 32 34 29 30 32 34 36 38 34 36 40 38 34 34 32 25 32 36 36 34 ...
result:
wrong answer 1st numbers differ - expected: '34', found: '32'