QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#794088 | #9802. Light Up the Grid | xiaoyilang | WA | 64ms | 16348kb | C++20 | 1.4kb | 2024-11-30 10:50:29 | 2024-11-30 10:50:30 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=16;
int T,m;
int a0,a1,a2,a3,h[N][N];
int dp[N][200005];
void init(){
memset(h,0x3f,sizeof(h));
int v1=min(a0,a1);
int v2=min(a2,a3);
for(int i=0;i<16;i++) h[i][i]=2*min(v1,v2);
for(int i=0;i<16;i++){
for(int j=0;j<4;j++){
int v=(i^(1<<j));
h[i][v]=min(h[i][v],a0);
}
for(int j=0;j<4;j+=2){
int v=(i^(1<<j));
v=(v^(1<<(j+1)));
h[i][v]=min(h[i][v],a1);
}
for(int j=0;j<2;j++){
int v=(i^(1<<j));
v=(v^(1<<(j+2)));
h[i][v]=min(h[i][v],a2);
}
h[i][i^15]=min(h[i][i^15],a3);
}
for(int k=0;k<16;k++){
for(int i=0;i<16;i++){
for(int j=0;j<16;j++)
h[i][j]=min(h[i][j],h[i][k]+h[k][j]);
}
}
memset(dp,0x3f,sizeof(dp));
dp[0][0]=0;
for(int i=0;i<16;i++){
for(int j=0;j<(1<<16);j++){
for(int k=0;k<16;k++){
if((j>>k)&1) continue;
int v=15-(k^i);
dp[i^v][j|(1<<k)]=min(dp[i^v][j|(1<<k)],dp[i][j]+h[0][v]);
}
}
}
return ;
}
void solve(){
cin>>m;
int sum=0;
while(m--){
string a,b;
cin>>a>>b;
int v=0;
for(int i=0;i<2;i++){
v=v*2+a[i]-'0';
}
for(int i=0;i<2;i++){
v=v*2+b[i]-'0';
}
sum|=(1<<v);
}
int ans=1e9;
for(int i=0;i<16;i++) ans=min(ans,dp[i][sum]);
cout<<ans<<'\n';
return ;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin>>T>>a0>>a1>>a2>>a3;
init();
while(T--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 58ms
memory: 16076kb
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: 57ms
memory: 16104kb
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: 57ms
memory: 16048kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 64ms
memory: 16348kb
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:
46 46 58 47 60 60 75 68 56 69 64 82 56 54 65 50 51 58 61 54 54 59 78 56 45 58 54 54 47 61 45 62 59 57 69 56 70 57 65 46 41 61 58 60 72 52 53 56 60 62 61 46 64 73 57 69 81 54 74 50 59 55 56 51 51 76 47 55 69 54 54 46 37 63 52 54 60 65 56 62 49 51 50 46 55 52 60 58 47 69 59 71 54 57 38 37 55 57 55 60 ...
result:
wrong answer 1st numbers differ - expected: '34', found: '46'