QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#822667 | #9802. Light Up the Grid | ucup-team2179# | WA | 42ms | 11824kb | C++23 | 1.6kb | 2024-12-20 15:26:28 | 2024-12-20 15:26:30 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define pii pair<int, int>
using namespace std;
const int maxn = (1 << 16) + 10;
int dp[maxn][16];
int pre[16][16];
int T, a0, a1, a2, a3;
void init() {
memset(pre, 0x3f, sizeof pre);
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 4; j++) {
pre[i][i ^ (1 << j)] = a0;
}
pre[i][i ^ 12] = pre[i][i ^ 3] = a1;
pre[i][i ^ 10] = pre[i][i ^ 5] = a2;
pre[i][i ^ 15] = a3;
}
for (int k = 0; k < 16; k++)
for (int i = 0; i < 16; i++)
for (int j = 0; j < 16; j++)
pre[i][j] = min(pre[i][j], pre[i][k] + pre[k][j]);
}
void solve() {
while (T--) {
int m; cin >> m;
int x = 0;
while (m--) {
int y = 0;
for (int i = 0; i < 4; i++) {
char ch; cin >> ch;
y = y * 2 + ch - '0';
}
x |= 1 << y;
}
int ans = dp[x][15];
cout << ans << "\n";
}
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> T >> a0 >> a1 >> a2 >> a3;
init();
memset(dp, 0x3f, sizeof dp);
for (int i = 0; i < 16; i++) dp[0][i] = 0;
for (int i = 0; i < (1 << 16); i++) {
for (int j = 0; j < 16; j++)
for (int k = 0; k < 16; k++) {
dp[i | (1 << (15 ^ k))][k] = min(dp[i | (1 << (15 ^ k))][k], dp[i][j] + pre[j][k]);
dp[i][k] = min(dp[i][k], dp[i][j] + pre[j][k]);
}
}
while (t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 33ms
memory: 11760kb
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: 34ms
memory: 11776kb
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: 37ms
memory: 11824kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 42ms
memory: 11780kb
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:
36 34 36 38 42 38 43 40 42 39 36 44 36 36 39 34 30 37 41 42 40 38 42 39 27 36 39 40 34 33 34 39 36 38 39 42 42 35 39 36 31 38 37 38 44 37 41 39 36 36 39 31 42 40 38 39 45 38 43 36 42 37 35 35 36 38 40 36 42 42 36 38 30 36 34 40 36 38 36 36 34 40 32 36 36 36 40 40 36 40 38 41 36 39 40 27 38 42 34 36 ...
result:
wrong answer 1st numbers differ - expected: '34', found: '36'