QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#787184 | #9802. Light Up the Grid | pengpeng_fudan | WA | 32ms | 11988kb | C++23 | 1.6kb | 2024-11-27 10:19:36 | 2024-11-29 22:56:13 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
int main() {
ios::sync_with_stdio(0),cin.tie(0);
int n;vector<ll> a(4);cin>>n;
for(int i=0;i<4;i++) cin>>a[i];
const ll INF=100000000000;
vector<vector<ll>> dis(16,vector<ll>(16,INF));
auto add=[&](int x,int y,ll v)->void {
dis[x][y]=min(dis[x][y],v);dis[y][x]=min(dis[y][x],v);
};
for(int i=0;i<16;i++){
for(int j=0;j<4;j++) add(i,(i^(1<<j)),a[0]);
add(i,i^3,a[1]);
add(i,i^6,a[1]);
add(i,i^5,a[2]);
add(i,i^10,a[2]);
add(i,i^15,a[3]);
}
for(int i=0;i<16;i++){
for(int j=0;j<16;j++){
for(int k=0;k<16;k++){
dis[j][k]=min(dis[j][k],dis[j][i]+dis[i][k]);
}
}
}
vector<vector<ll>> dp(16,vector<ll>(1<<16,INF));
dp[15][0]=0;
for(int i=0;i<(1<<16);i++){
for(int j=0;j<16;j++){
if(dp[j][i]==INF) continue;
for(int k=0;k<16;k++){
if(!((i>>k)&1)) {
dp[k][i|(1<<k)]=min(dp[k][i|(1<<k)],dp[j][i]+dis[j][k]);
}
}
}
}
for(int i=1;i<=n;i++){
int m;cin>>m;
int num=0;
for(int j=1;j<=m;j++){
string a,b;
cin>>a>>b;a+=b;
int ret=0;
for(auto i:a){
ret=(ret<<1)+(i-'0');
}
num|=(1<<ret);
}
ll ans=INF;
for(int j=0;j<16;j++){
ans=min(ans,dp[j][num]);
}
cout<<ans<<'\n';
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 26ms
memory: 11988kb
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: 29ms
memory: 11948kb
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: 29ms
memory: 11736kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 32ms
memory: 11784kb
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:
39 35 36 37 40 39 44 41 38 39 39 46 37 37 39 37 37 37 37 36 38 38 42 34 31 35 34 37 33 40 35 38 40 37 38 40 40 34 38 31 29 39 36 38 42 37 35 37 38 40 34 35 36 40 36 38 40 40 38 37 39 37 32 36 35 41 29 38 41 35 38 36 27 40 38 43 41 40 36 36 29 31 40 35 37 35 36 37 38 41 38 42 31 36 29 33 36 34 36 34 ...
result:
wrong answer 1st numbers differ - expected: '34', found: '39'