QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#790277 | #9802. Light Up the Grid | MYdinosaur | WA | 77ms | 4728kb | C++14 | 3.1kb | 2024-11-28 09:34:59 | 2024-11-28 09:34:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pa;
const int N = 1 << 17;
int cost[5];
ll a[20];
int m;
int T;
ll sum = 0;
ll ans = 1e9 + 10;
ll f[20][20];
int vis[20];
ll pat[N];
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;
}
void dg(int dep, int x, ll g, ll gh)
{
if (g >= ans) return;
if (dep == 16)
{
return;
}
for (int i = 0; i <= 15; i++)
{
if (vis[i]) continue;
int fg = gh | (1 << i);
// if (i == 15 && x == 15 )cout << i << " " << x << " " << f[i][x] << " " << g << endl;
if (g + f[i][x] >= pat[fg]) continue;
pat[fg] = g + f[i][x];
vis[i] = 1;
dg(dep + 1, i, g + f[i][x], fg);
vis[i] = 0;
}
}
void prepare()
{
memset(pat, 0x3f3f3f, sizeof(pat));
memset(f, 0x3f3f3f, sizeof(f));
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;
dg(0, 15, 0, 0);
}
int main()
{
// freopen("1.out","w",stdout);
prepare();
// cout << T << " " << f[15][15] << endl;
while (T > 0)
{
T--;
// int m;
int tot = 0;
read(m);
int p = 0;
ll sum = 0;
// cout << m << endl;
int jl = 0;
for (int k = 1; k <= m; k++)
{
vis[k] = 0;
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;
}
}
jl |= 1 << a[k];
}
sum = pat[jl];
// cout << jl << endl;
cout << sum << endl;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 77ms
memory: 4592kb
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: 10ms
memory: 4728kb
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: 10ms
memory: 4656kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 53ms
memory: 4652kb
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:
34 32 36 36 40 38 42 38 40 41 36 44 34 37 37 33 29 40 39 40 38 39 44 37 29 38 37 38 34 35 32 41 34 36 41 40 45 34 37 34 29 36 40 40 43 36 39 38 38 38 42 29 41 44 36 44 45 40 41 35 42 39 37 33 34 39 38 37 42 40 34 36 29 34 34 40 36 39 38 40 36 39 35 35 36 34 42 41 38 39 40 42 37 42 38 29 36 40 36 35 ...
result:
wrong answer 6th numbers differ - expected: '36', found: '38'