QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#787309 | #9802. Light Up the Grid | tilenn | TL | 0ms | 0kb | C++14 | 2.0kb | 2024-11-27 11:03:29 | 2024-11-27 11:03:29 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long LL;
typedef unsigned long long ULL;
vector<LL> a(4);
vector<pair<ULL,LL>> md;
vector<LL> dist(1 << 16,1e9);
struct Node{
ULL f,g;
bool operator<(Node a) const {
if(f == a.f)return g < a.g;
return f < a.f;
}
};
void init(){
priority_queue<pair<LL,Node>,vector<pair<LL,Node>>,greater<pair<LL,Node>>> q;
map<Node,LL> mp;
Node tmp;
tmp.f = tmp.g = 0;
for(int i = 0;i < 16;i++){
tmp.f |= ULL(i) << (4 * i);
}
q.push({0,tmp});
int co = 0;
while(q.size()){
auto [w,s] = q.top();
q.pop();
if(mp[s] < w)continue;
for(int i = s.g;i > 0;i = (i - 1) & s.g){
dist[i] = min(dist[i],w);
}
for(auto [t,c] : md){
auto mk = s;
for(int i = 0;i < 16;i++){
mk.f ^= t << (4 * i);
if((mk.f >> (4 * i) & 15) == 15){
mk.g |= 1LL << i;
}
}
if(!mp.count(mk) || mp[mk] > w + c){
mp[mk] = w + c;
q.push({w + c,mk});
}
}
}
}
void solve(){
int n;
cin >> n;
int s = 0;
for(int i = 1;i <= n;i++){
string x,y;
cin >> x >> y;
int z = 0;
z += 8 * (x[0] - '0');
z += 4 * (x[1] - '0');
z += 2 * (y[0] - '0');
z += (y[1] - '0');
s += 1 << z;
}
cout << dist[s] << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL),cout.tie(NULL);
int t = 1;
cin >> t;
cin >> a[0] >> a[1] >> a[2] >> a[3];
for(int i = 0;i < 4;i++){
md.push_back({1 << i,a[0]});
}
md.push_back({12,a[1]});
md.push_back({3,a[1]});
md.push_back({10,a[2]});
md.push_back({5,a[2]});
md.push_back({15,a[3]});
init();
while(t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
2 1000 100 10 1 4 10 00 01 00 00 10 00 01 1 11 11