QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#785015 | #9802. Light Up the Grid | Qzong# | WA | 429ms | 10648kb | C++14 | 1.8kb | 2024-11-26 16:38:11 | 2024-11-26 16:38:12 |
Judging History
answer
#include<cstdio>
#include<cstring>
int min(int x,int y){
return x<y?x:y;
}
int max(int x,int y){
return x>y?x:y;
}
int a0,a1,a2,a3;
int go(int x){
// x^=15;
if(x==15)return min(4*a0,min(2*a1,min(2*a2,a3)));
if(x==1||x==2||x==4||x==8)return a0;
if(x==6||x==9)return min(2*a0,a1+a2);
if(x==0)return 0;
if(x==3||x==12)return min(a1,2*a0);
if(x==5||x==10)return min(a2,2*a0);
return min(a0+a1,min(a0+a2,min(3*a0,a3+a0)));
}
int f[18][4];
int g[1<<17|10][17];
void work(){
int m;
scanf("%d",&m);
char s[4];
int all=0;
for(int i=1;i<=m;i++){
int now=0;
scanf("%s",s);
now=now*2+s[0]-'0';
now=now*2+s[1]-'0';
scanf("%s",s);
now=now*2+s[0]-'0';
now=now*2+s[1]-'0';
all|=(1<<now);
// printf("%d\n",now);
}
int ans=2000000000;
// printf("%d === \n",g[(1<<2)|(1<<8)][2]);
for(int i=0;i<16;i++)ans=min(ans,g[all][i]);
// printf("%d---\n",all);
if(ans==0)printf("%d\n",2*(min(a0,min(a1,min(a2,a3)))));
else printf("%d\n",ans);
}
int tmp[1<<17|10];
void init(){
memset(g,63,sizeof g);
// g[1<<15][15]=0;
// int now=0;
// for(int S=0;S<(1<<16);S++)g[S]
for(int i=0;i<16;i++)g[0][i]=0;
for(int k=1;k<=16;k++){
for(int S=0;S<(1<<16);S++){
for(int i=0;i<=15;i++){
for(int j=0;j<=15;j++){
if(!(S&(1<<i))){
// puts("YUes");
g[S|(1<<i)][i]=min(g[S][j]+(S==0?go(15^i):go(i^j)),g[S|(1<<i)][i]);
}
}
}
}
}
}
int main(){
// freopen("a.in","r",stdin);
int t;
scanf("%d%d%d%d%d",&t,&a0,&a1,&a2,&a3);
init();
while(t--)work();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 425ms
memory: 10248kb
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: 417ms
memory: 10288kb
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: 421ms
memory: 10648kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 429ms
memory: 10304kb
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'