QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#800093 | #9802. Light Up the Grid | pemguimn | WA | 45ms | 19224kb | C++14 | 2.1kb | 2024-12-05 21:34:07 | 2024-12-05 21:34:07 |
Judging History
answer
#include <bits/stdc++.h>
#define pii pair<int, int>
using namespace std;
const int INF = 1e9 + 7, M = 16, COMPLETE = 1 << 15;
vector<pii> edge;
vector<pii> adj[1 << M];
int d[1 << M];
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t, a1, a2, a3, a4; cin >> t >> a1 >> a2 >> a3 >> a4;
for(int i = 0; i < 4; i++) edge.push_back({a1, (1 << i)});
for(int i = 0; i < 4; i += 2) edge.push_back({a2, (1 << i) | (1 << (i + 1))});
for(int i = 0; i < 2; i += 1) edge.push_back({a3, (1 << i) | (1 << (i + 2))});
edge.push_back({a4, (1 << 4) - 1});
vector<int> x;
for(int mask = 0; mask < (1 << M); mask++){
for(int i = 0; i < M; i++){
if(mask & (1 << i)) x.push_back(i);
}
for(pii e : edge){
int nmask = 0;
for(int y : x){
if((y ^ e.second) != 15) nmask |= (1 << (y ^ e.second));
}
adj[nmask].push_back({mask, e.first});
adj[mask].push_back({nmask, e.first});
}
x.clear();
}
for(int i = 0; i < 1 << M; i++) d[i] = INF;
d[COMPLETE] = 0; priority_queue<pii> pq;
pq.push({-d[COMPLETE], COMPLETE});
while(!pq.empty()){
pii cur = pq.top(); pq.pop();
if(-cur.first != d[cur.second]) continue;
int mask = cur.second;
for(pii e : adj[mask]){
if(d[e.first] > d[mask] + e.second){
d[e.first] = d[mask] + e.second;
pq.push({-d[e.first], e.first});
}
}
}
for(int i = 1; i <= t; i++){
int m; cin >> m;
int mask = 0;
while(m--){
int bit = 0;
for(int r = 0; r < 2; r++){
for(int c = 0; c < 2; c++){
char ch; cin >> ch;
bit |= ((ch - '0') << (r * 2 + c));
}
}
mask |= (1 << bit);
}
cout << d[mask] + ((mask & COMPLETE) ? 2 * d[1] : 0) << '\n';
}
return 0;
}
/*
2 1000 100 10 1
4
10
00
01
00
00
10
00
01
1
11
11
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 41ms
memory: 19224kb
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: 30ms
memory: 19164kb
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: 36ms
memory: 19052kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 45ms
memory: 19224kb
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:
42 40 44 44 48 36 50 38 40 49 44 52 34 37 37 40 29 47 39 40 38 47 52 45 37 45 45 38 34 42 32 49 42 44 49 48 52 34 37 34 29 44 47 48 50 35 47 45 38 46 49 29 48 49 36 49 43 48 41 42 50 39 45 41 34 46 46 45 42 40 42 44 28 34 32 46 44 39 46 37 44 46 42 42 42 34 50 40 46 46 40 48 45 48 46 37 36 40 36 34 ...
result:
wrong answer 1st numbers differ - expected: '34', found: '42'