QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#783629 | #9802. Light Up the Grid | solunar | TL | 1ms | 3828kb | C++14 | 1.2kb | 2024-11-26 11:06:04 | 2024-11-26 11:06:04 |
Judging History
answer
// 2024ICPCShenyangE
#include <iostream>
#include <algorithm>
using namespace std;
#include <math.h>
#include <memory.h>
int m;
int a1, a2, a3, a4;
char ope[9] = {1, 2, 4, 8, 3, 12, 5, 10, 15 };
int a[9];
int grid;
int dp[1<<16];
int memoir(int s) {
if (s == 0)
return dp[s] = 0;
dp[s] = 2e9;
for (int i = 0; i < 9; i++) {
int news = 0;
for (int j = 0; j < 16; j++)
if ((s & (1 << j)) && ((j ^ ope[i]) != 15))
news |= (1 << (j ^ ope[i]));
int suba = (dp[news] >= 0) ? dp[news] : memoir(news);
dp[s] = min(dp[s], a[i] + suba);
}
return dp[s];
}
int main() {
int t, init15;
char ch;
cin >> t >> a1 >> a2 >> a3 >> a4;
a[0] = a[1] = a[2] = a[3] = a1;
a[4] = a[5] = a2;
a[6] = a[7] = a3;
a[8] = a4;
while (t--) {
cin >> m;
init15 = false;
int s = 0;
for (int i = 0; i < m; i++) {
grid = 0;
for (int j = 0; j < 4; j++) {
cin >> ch;
if (ch == '1')
grid |= (1 << j);
}
if (grid == 15)
init15 = true;
s |= (1 << grid);
}
memset(dp, 0xff, sizeof(dp));
int ans = memoir(s);
cout << ans << endl;
}
return 0;
}
/*
1 1000 100 10 1
1
10
11
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3820kb
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: 1ms
memory: 3780kb
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: 3828kb
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 41 41 36 44 34 37 37 32 29 39 39 40 38 39 45 37 29 37 38 38 34 34 32 41 34 36 41 40 44 34 37 34 29 36 39 40 42 35 40 37 38 38 41 29 40 41 36 41 43 40 42 34 42 39 38 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 40 37 40 38 29 36 40 36 34 ...