QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#815685 | #9802. Light Up the Grid | KafuuChinocpp# | Compile Error | / | / | C++14 | 2.5kb | 2024-12-15 16:25:33 | 2024-12-15 16:25:35 |
Judging History
answer
#include <cstdio>
#include <algorithm>
using namespace std;
const int max1 = 16, max2 = 1 << max1;
const int inf = 0x3f3f3f3f;
int T, a[4];
int edge[max1 + 5][max1 + 5];
int f[max2 + 5][max1 + 5];
int main ()
{
scanf("%d%d%d%d%d", &T, &a[0], &a[1], &a[2], &a[3]);
memset(edge, 0x3f, sizeof(edge));
for ( int i = 0; i < max1; i ++ )
edge[i][i] = 0;
for ( int i = 0; i < max1; i ++ )
{
int t = i ^ 1;
edge[i][t] = min(edge[i][t], a[0]);
t = i ^ 2;
edge[i][t] = min(edge[i][t], a[0]);
t = i ^ 4;
edge[i][t] = min(edge[i][t], a[0]);
t = i ^ 8;
edge[i][t] = min(edge[i][t], a[0]);
t = i ^ 1 ^ 2;
edge[i][t] = min(edge[i][t], a[1]);
t = i ^ 4 ^ 8;
edge[i][t] = min(edge[i][t], a[1]);
t = i ^ 1 ^ 4;
edge[i][t] = min(edge[i][t], a[2]);
t = i ^ 2 ^ 8;
edge[i][t] = min(edge[i][t], a[2]);
t = i ^ 1 ^ 2 ^ 4 ^ 8;
edge[i][t] = min(edge[i][t], a[3]);
}
for ( int k = 0; k < max1; k ++ )
for ( int i = 0; i < max1; i ++ )
for ( int j = 0; j < max1; j ++ )
edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j]);
memset(f, 0x3f, sizeof(f));
f[0][max1 - 1] = 0;
for ( int s = 0; s < max2; s ++ )
{
for ( int i = 0; i < max1; i ++ )
{
if ( f[s][i] != inf )
{
for ( int j = 0; j < max1; j ++ )
{
if ( !((s >> j) & 1) )
{
f[s | (1 << j)][j] = min(f[s | (1 << j)][j], f[s][i] + edge[i][j]);
}
}
}
}
}
int k;
char str[5][5];
while ( T -- )
{
scanf("%d", &k);
int s = 0, x = 0;
for ( int i = 1; i <= k; i ++ )
{
scanf("%s", str[0]);
scanf("%s", str[1]);
x = (str[0][0] - '0') | ((str[0][1] - '0') << 1) | ((str[1][0] - '0') << 2) | ((str[1][1] - '0') << 3);
s |= 1 << x;
// printf("x = %d\n", x);
}
int ans = inf;
for ( int i = 0; i < max1; i ++ )
ans = min(ans, f[s][i]);
if ( !ans )
ans = min(a[0], min(a[1], min(a[2], a[3]))) * 2;
printf("%d\n", ans);
}
return 0;
}
Details
answer.code: In function ‘int main()’: answer.code:18:5: error: ‘memset’ was not declared in this scope 18 | memset(edge, 0x3f, sizeof(edge)); | ^~~~~~ answer.code:3:1: note: ‘memset’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’? 2 | #include <algorithm> +++ |+#include <cstring> 3 | answer.code:16:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 16 | scanf("%d%d%d%d%d", &T, &a[0], &a[1], &a[2], &a[3]); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ answer.code:81:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 81 | scanf("%d", &k); | ~~~~~^~~~~~~~~~ answer.code:86:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 86 | scanf("%s", str[0]); | ~~~~~^~~~~~~~~~~~~~ answer.code:87:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 87 | scanf("%s", str[1]); | ~~~~~^~~~~~~~~~~~~~