QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#811058 | #9802. Light Up the Grid | rotcar07 | WA | 14ms | 4192kb | C++23 | 1008b | 2024-12-12 15:02:02 | 2024-12-12 15:02:02 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int a[4],f[1<<16];
constexpr pair<int,int> sk[]={{1,0},{2,0},{4,0},{8,0},{3,1},{12,1},{5,2},{10,2},{15,3}};
inline void solve(){
int m=0;int msk=0;
cin>>m;
while(m--){
char a,b,c,d;cin>>a>>b>>c>>d;
msk|=1<<((a-'0')+(b-'0')*2+(c-'0')*4+(d-'0')*8);
}
cout<<f[msk]<<'\n';
}
int main(){
std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t;cin>>t>>a[0]>>a[1]>>a[2]>>a[3];
memset(f,0x3f,sizeof f);
priority_queue<pair<int,int>> q;q.emplace(0,1<<15);f[1<<15]=0;
while(!q.empty()){
auto [dis,p]=q.top();q.pop();dis=-dis;
if(f[p]!=dis) continue;
vector<int> v;
auto upd=[&](int to,int dis){if(f[to]>dis)f[to]=dis,q.emplace(-dis,to);};
for(int j=0;j<16;j++) if(p>>j&1) v.push_back(j);
for(auto [ff,y]:sk){
int to=1<<15;
for(int x:v) to|=1<<(x^ff);
upd(to,dis+a[y]);
}
}
for(int i=0;i<16;i++)
for(int j=0;j<1<<16;j++)if(j>>i&1)f[j^1<<i]=min(f[j^1<<i],f[j]);
f[1<<15]=2;
while(t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 14ms
memory: 3872kb
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: 6ms
memory: 3968kb
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: -100
Wrong Answer
time: 9ms
memory: 4192kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2
result:
wrong answer 1st numbers differ - expected: '2000000', found: '2'