QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#787306 | #9802. Light Up the Grid | tilenn | WA | 162ms | 8212kb | C++14 | 2.0kb | 2024-11-27 11:02:44 | 2024-11-29 22:56:24 |
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 {
return g < a.g;
}
bool operator>(Node a) const {
return g > a.g;
}
};
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 162ms
memory: 8212kb
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: 127ms
memory: 7904kb
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: 123ms
memory: 7776kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 159ms
memory: 8064kb
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 37 42 36 42 38 40 42 36 44 34 37 38 32 29 39 40 40 38 40 46 38 31 38 37 38 34 35 32 41 34 36 41 40 45 34 38 34 29 36 40 40 43 35 40 38 38 38 42 29 41 41 36 42 44 40 42 35 42 40 38 33 34 39 38 37 42 40 34 36 29 34 34 38 36 40 38 37 36 38 35 34 36 34 42 40 38 40 40 40 38 42 38 29 36 40 36 36 ...
result:
wrong answer 4th numbers differ - expected: '36', found: '37'