QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#794097 | #9802. Light Up the Grid | xiaoyilang | WA | 34ms | 16264kb | C++20 | 1.5kb | 2024-11-30 10:58:31 | 2024-11-30 10:58:31 |
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]=0;
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 j=0;j<(1<<16);j++){
for(int i=0;i<16;i++){
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[i][i^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]);
ans=max(ans,2*min({a0,a1,a2,a3}));
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: 28ms
memory: 16040kb
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: 24ms
memory: 16264kb
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: 25ms
memory: 16044kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 34ms
memory: 16116kb
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 41 38 40 37 34 42 34 37 37 31 29 35 39 40 38 36 40 34 25 34 34 38 34 31 32 37 34 36 37 40 40 34 37 34 29 35 35 36 42 35 35 34 38 34 37 29 38 38 36 37 43 36 41 30 40 39 33 33 34 36 34 34 42 40 34 32 28 34 32 37 34 39 34 37 32 36 30 30 32 34 38 40 34 36 40 39 34 36 34 25 36 40 36 34 ...
result:
wrong answer 1st numbers differ - expected: '34', found: '32'