QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#821975 | #9802. Light Up the Grid | ucup-team093# | TL | 982ms | 8108kb | C++20 | 1.7kb | 2024-12-19 20:01:25 | 2024-12-19 20:01:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using node = tuple<int, int, int>;
int q, w[4], a[1 << 4], dp[1 << 4][1 << 16], ans[1 << 16];
/*
01
23
12
48
*/
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> q >> w[0] >> w[1] >> w[2] >> w[3];
a[1] = a[2] = a[4] = a[8] = w[0];
a[1 + 2] = a[4 + 8] = w[1];
a[1 + 4] = a[2 + 8] = w[2];
a[1 + 2 + 4 + 8] = w[3];
vector<int> e;
for(int i = 0; i < 16; i ++) if(a[i]) e.push_back(i);
memset(dp, 0x7f, sizeof dp);
memset(ans, 0x7f, sizeof ans);
dp[0][0] = 0;
{
priority_queue<node> q;
q.push({0, 0, 0});
while(q.size()) {
auto [x, u, b] = q.top();
q.pop();
if(x > dp[u][b]) continue;
//cout << x << " " << bitset<4>(u) << " " << bitset<16>(b) << "\n";
ans[b] = min(ans[b], x);
for(int msk : e) {
int v = u ^ msk, tb = b | (1 << v);
if(x + a[msk] < dp[v][tb]) {
dp[v][tb] = x + a[msk];
q.push({x + a[msk], v, tb});
}
}
}
}
for(int i = 0; i < 16; i ++)
for(int j = 0; j < (1 << 16); j ++)
if(!((j >> i) & 1)) ans[j] = min(ans[j], ans[j ^ (1 << i)]);
while(q --) {
int m, msk = 0;
cin >> m;
for(int i = 1; i <= m; i ++) {
char c[4];
cin >> c[0] >> c[1] >> c[2] >> c[3];
msk |= 1 << (15 ^ ((c[0] - '0') * 1 + (c[1] - '0') * 2 + (c[2] - '0') * 4 + (c[3] - '0') * 8));
}
//cout << bitset<16>(msk) << " ";
cout << ans[msk] << "\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 943ms
memory: 7972kb
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: 284ms
memory: 7876kb
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: 283ms
memory: 7948kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: 0
Accepted
time: 776ms
memory: 7920kb
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 40 37 40 38 29 36 40 36 34 ...
result:
ok 10000 numbers
Test #5:
score: 0
Accepted
time: 714ms
memory: 8052kb
input:
10000 73 78 73 17 11 01 10 01 11 10 00 11 11 00 00 11 01 10 11 11 10 00 11 10 01 01 00 6 00 00 10 11 11 10 01 01 11 01 11 00 7 01 11 01 00 10 00 10 11 10 10 00 00 01 01 10 10 01 10 10 00 10 10 11 10 00 01 01 01 10 11 11 11 00 00 01 10 11 11 01 11 10 10 01 01 00 01 ...
output:
523 382 287 579 523 596 343 275 343 472 382 343 455 326 433 360 579 545 506 523 326 528 467 382 438 421 377 460 416 579 489 596 309 326 326 596 438 387 506 562 523 377 416 309 523 348 365 343 416 392 343 399 348 506 421 596 450 426 579 370 506 185 489 377 489 387 416 472 314 489 506 450 421 433 416 ...
result:
ok 10000 numbers
Test #6:
score: 0
Accepted
time: 893ms
memory: 7944kb
input:
10000 701 328 455 703 7 10 11 00 01 00 11 00 10 01 00 11 11 11 00 7 00 01 01 00 00 11 11 11 00 00 11 10 11 01 6 01 10 01 01 00 01 00 11 10 01 11 00 8 00 11 10 11 00 10 00 01 11 10 01 01 10 10 11 00 5 00 11 10 11 11 00 01 10 01 00 7 00 01 10 10 11 01 00 10 10 00 11 11...
output:
3124 3124 2595 4153 2595 3177 3907 2796 4235 3833 3296 2595 4809 3579 3579 3050 3169 3907 3907 3251 3169 2714 2595 3050 3251 3542 2796 3251 4563 3251 3452 3907 3251 3251 4034 4034 1730 2140 3087 4153 3907 3907 4727 4809 2923 3497 3579 3431 3251 4235 2267 4354 2595 4153 3169 4727 3087 4235 3579 2595 ...
result:
ok 10000 numbers
Test #7:
score: 0
Accepted
time: 827ms
memory: 7896kb
input:
10000 6459 225 8979 7226 16 00 11 11 01 10 01 10 10 00 01 01 11 11 00 11 11 00 10 11 10 01 01 01 00 01 10 10 00 00 00 10 11 16 10 00 11 10 01 10 11 11 00 01 00 00 01 00 01 11 01 01 10 01 00 10 10 10 00 11 11 01 10 11 11 00 16 10 11 01 11 10 00 10 10 01 00 11 11 01...
output:
22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 22302 ...
result:
ok 10000 numbers
Test #8:
score: 0
Accepted
time: 823ms
memory: 7976kb
input:
10000 47809 35506 569 26740 5 00 01 10 10 11 01 11 11 00 11 8 11 01 10 10 11 00 01 00 10 01 01 10 10 00 00 10 6 01 10 11 00 00 11 11 11 10 01 01 01 8 00 10 10 01 01 10 10 11 00 00 00 11 01 01 11 10 6 01 11 10 01 00 10 00 00 10 00 01 10 8 00 01 01 10 01 11 00 00 10 10 ...
output:
119959 122235 38351 122235 87298 122235 122804 122804 122804 85591 123373 123942 121097 86160 122235 123942 122235 85591 86729 124511 122804 122235 88436 123373 122804 122235 124511 85591 121666 49516 122235 122235 122235 121666 86160 121097 125649 123373 87867 121097 123373 123942 123373 120528 123...
result:
ok 10000 numbers
Test #9:
score: 0
Accepted
time: 982ms
memory: 7948kb
input:
10000 947705 1031 121092 212797 8 00 01 10 11 01 11 01 01 00 10 11 10 11 00 01 10 10 00 10 11 01 10 11 00 11 01 00 11 11 00 00 10 01 00 01 10 00 8 11 11 11 00 01 11 10 10 10 11 01 01 00 01 10 00 8 01 00 11 00 00 01 11 01 01 01 10 11 10 01 11 11 8 00 01 11 11 11 10 00...
output:
1195044 1200199 1197106 1196075 1074983 1199168 1197106 1198137 1201230 1197106 1199168 1197106 1195044 1198137 1197106 1197106 1199168 1198137 1198137 1198137 1076014 1196075 1199168 1197106 1197106 1197106 1197106 1195044 1198137 1198137 1200199 1196075 1202261 1198137 1198137 1199168 1196075 1196...
result:
ok 10000 numbers
Test #10:
score: 0
Accepted
time: 739ms
memory: 8108kb
input:
10000 9 3 5 10 16 01 11 10 11 11 00 00 10 01 01 01 10 10 10 00 11 11 10 00 01 01 00 11 01 10 01 10 00 00 00 11 11 16 11 11 00 10 01 01 01 00 10 10 10 01 11 10 11 01 11 00 10 11 01 10 01 11 10 00 00 00 00 11 00 01 16 00 00 11 00 00 10 10 11 11 10 01 11 01 00 10 00...
output:
58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 ...
result:
ok 10000 numbers
Test #11:
score: -100
Time Limit Exceeded
input:
10000 366 23 191 94 10 10 10 11 11 10 01 11 01 00 10 10 00 01 11 11 10 00 11 10 11 9 00 00 00 01 11 00 11 10 01 10 11 11 10 11 01 11 00 10 12 11 01 01 00 00 11 00 00 11 10 01 11 11 11 00 10 00 01 10 10 01 01 01 10 9 11 01 01 01 00 10 10 11 11 10 01 10 11 00 11 11 ...
output:
909 932 978 886 886 932 909 863 932 863 886 955 886 932 955 909 978 909 932 909 932 955 863 978 909 932 863 886 978 955 863 932 932 718 955 718 932 909 955 932 978 932 886 932 1024 932 932 932 1001 718 955 886 909 909 909 978 978 764 978 863 909 955 909 932 886 978 955 909 718 978 863 932 1001 1001 ...