QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#780729 | #9802. Light Up the Grid | aYi_7# | WA | 435ms | 3672kb | C++23 | 3.1kb | 2024-11-25 12:51:23 | 2024-11-25 12:51:24 |
Judging History
answer
#include <bits/stdc++.h>
#define b4 bitset<4>
#define int long long
using namespace std;
const int mod = 998244353;
const int N = 1e5 + 7;
int d[16][16];
b4 bs[16];
struct node{
b4 s;
int cost;
};
struct cmp{
bool operator () (node a,node b){
return (a.cost>b.cost);
}
};
int vs(b4 &s){return 1*s[0]+2*s[1]+4*s[2]+8*s[3];}
int mm=LONG_LONG_MAX;
void solve() {
int m;
cin>>m;
set<int>hh;
for(int i=0;i<m;i++){
string q,w;cin>>q>>w;
q+=w;
bitset<4>s(q);
hh.insert(vs(s));
}
int ans=LONG_LONG_MAX;
for(int cur:hh){
set<int>h=hh;
int cost=0;
cost+=d[cur][15];
h.erase(cur);
function<void(int)>dfs=[&](int cur){
if(h.empty()){
ans=min(ans,cost);
return ;
}
vector<int>v;
int to=*h.begin(),ct=d[cur][to];
for(int s:h)if(d[cur][s]<ct){to=s;ct=d[cur][to];}
for(int s:h)if(d[cur][s]==ct)v.emplace_back(s);
cost+=ct;
for(int s:v){
h.erase(s);
dfs(s);
h.insert(s);
}
cost-=ct;
};
dfs(cur);
// while(!h.empty()){
// int to=*h.begin(),ct=d[cur][to];
// for(int s:h)if(d[cur][s]<ct){to=s;ct=d[cur][to];}
// cost+=ct;
// cur=to;
// h.erase(to);
// }
// ans=min(ans,cost);
}
if(ans==0)ans=mm;
cout<<ans<<"\n";
}
/*
2 1000 100 10 1
4
10
00
01
00
00
10
00
01
1
11
11
1 1000 100 10 1
7
10
01
10
00
00
11
11
10
01
00
11
00
01
11
* */
signed main() {
for(auto & i : d)
for(auto & j : i)
j=-1;
for(int i=0;i<16;++i){
bitset<4> s("0000");
int id=i;
for(int j=0;j<4;++j){
if(id&1)s[j]=1;
id>>=1;
}
bs[i]=s;
}
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
cin >> t;
int a0,a1,a2,a3;cin>>a0>>a1>>a2>>a3;
mm=min({a0,a1,a2,a3})*2ll;
for(int i=0;i<16;++i){
priority_queue<node,vector<node>,cmp>q;
q.push({bs[i],0});
while(!q.empty()){
b4 s=q.top().s;
int cost=q.top().cost;
int id=vs(s);
q.pop();
if(d[i][id]!=-1)continue;
d[i][id]=cost;
b4 r;
for(int j=0;j<4;++j){r=s;r[j]=!r[j];if(d[i][vs(r)]==-1)q.push({r,cost+a0});}
r=s;r[0]=!r[0];r[1]=!r[1];if(d[i][vs(r)]==-1)q.push({r,cost+a1});
r=s;r[2]=!r[2];r[3]=!r[3];if(d[i][vs(r)]==-1)q.push({r,cost+a1});
r=s;r[0]=!r[0];r[2]=!r[2];if(d[i][vs(r)]==-1)q.push({r,cost+a2});
r=s;r[1]=!r[1];r[3]=!r[3];if(d[i][vs(r)]==-1)q.push({r,cost+a2});
r=s;r[0]=!r[0];r[1]=!r[1];r[2]=!r[2];r[3]=!r[3];if(d[i][vs(r)]==-1)q.push({r,cost+a3});
}
}
for (int i = 0; i < t; ++i) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
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: 0ms
memory: 3568kb
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: 0ms
memory: 3672kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 435ms
memory: 3616kb
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:
32 30 34 34 40 36 42 38 40 38 34 42 34 37 37 31 29 35 40 40 38 36 40 34 25 34 34 38 34 31 32 38 34 36 38 40 42 34 37 34 29 36 36 36 43 35 35 34 38 34 38 29 38 38 36 38 44 36 41 30 40 40 33 33 34 36 34 34 42 40 34 32 29 34 32 38 34 39 34 38 32 36 31 30 32 34 38 42 34 36 40 40 34 38 34 25 36 40 36 34 ...
result:
wrong answer 1st numbers differ - expected: '34', found: '32'