QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#790055 | #9802. Light Up the Grid | MYdinosaur | TL | 0ms | 3692kb | C++14 | 2.8kb | 2024-11-28 00:07:02 | 2024-11-28 00:07:04 |
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];
int m;
ll sum = 0;
ll ans = 1e9 + 10;
ll f[20][20];
int vis[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]);
}
void dg(int dep, int x, ll g)
{
if (g >= ans) return;
if (dep == m)
{
ans = min(ans, g);
return;
}
for (int i = 1; i <= m; i++)
{
if (vis[i]) continue;
vis[i] = 1;
dg(dep + 1, i, g + f[a[i]][a[x]]);
vis[i] = 0;
}
}
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;
ll sum = 0;
// cout << m << endl;
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;
}
}
}
sum = 0;
ans = 1e9 + 10;
a[0] = 15;
dg(0, 0, 0);
cout << ans << endl;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3692kb
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: 3688kb
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: 3508kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Time Limit Exceeded
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 36 42 38 40 41 36 44 34 37 37 32 29 39 39 40 38 39 44 37 29 37 37 38 34 34 32 41 34 36 41 40 44 34 37 34 29 36 39 40 42 35 39 37 38 38 41 29 40 41 36 41 43 40 41 34 42 39 37 33 34 38 38 37 42 40 34 36 28 34 32 38 36 39 38 37 36 38 34 34 34 34 42 40 38 38 40