QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#858325 | #9802. Light Up the Grid | Nana7# | WA | 50ms | 9272kb | C++14 | 1.6kb | 2025-01-16 16:16:16 | 2025-01-16 16:16:17 |
Judging History
answer
#include<bits/stdc++.h>
#define I inline
using namespace std;
int f[22][65540];
int d[22][22];
int pw[22];
int n,a[22];
char s[3][3];
int a0,a1,a2,a3;
I void init() {
memset(d,0x2f,sizeof(d));
//for(int i=0;i<16;++i) d[i][i]=0;
for(int i=0;i<16;++i) {
for(int j=0;j<4;++j) {
d[i][i^pw[j]]=min(d[i][i^pw[j]],a0);
}
}
for(int i=0;i<16;++i) {
d[i][i^(1+2)]=min(d[i][i^(1+2)],a1);
d[i][i^(4+8)]=min(d[i][i^(4+8)],a1);
}
for(int i=0;i<16;++i) {
d[i][i^(1+4)]=min(d[i][i^(1+4)],a2);
d[i][i^(2+8)]=min(d[i][i^(2+8)],a2);
}
for(int i=0;i<16;++i) d[i][i^15]=min(d[i][i^15],a3);
for(int i=0;i<16;++i) {
for(int j=0;j<16;++j) {
for(int p=0;p<16;++p) {
d[j][p]=min(d[j][p],d[j][i]+d[i][p]);
}
}
}
memset(f,0x2f,sizeof(f));
for(int i=0;i<16;++i) f[i][pw[i]]=d[i][15];
for(int i=0;i<16;++i) {
for(int j=0;j<pw[16];++j) {
for(int p=0;p<16;++p) {
f[p][j|pw[p]]=min(f[p][j|pw[p]],f[i][j]-d[i][15]+d[i][p]+d[p][15]);
}
}
}
}
I void solve() {
cin>>n;
for(int i=1;i<=n;++i) {
a[i]=0;
cin>>s[1];
cin>>s[2];
if(s[1][0]=='1') a[i]+=pw[0];
if(s[1][1]=='1') a[i]+=pw[1];
if(s[2][0]=='1') a[i]+=pw[2];
if(s[2][1]=='1') a[i]+=pw[3];
}
int ans=1e9,msk=0;
for(int i=1;i<=n;++i) msk|=pw[a[i]];
for(int j=0;j<16;++j) ans=min(ans,f[j][msk]);
cout<<ans<<endl;
}
/*
2 1000 100 10 1
4
10
00
01
00
00
10
00
01
1
11
11
*/
int main()
{
{
pw[0]=1;
for(int i=1;i<=16;++i) pw[i]=pw[i-1]<<1;
}
//cout<<pw[16]<<endl;
int T; cin>>T>>a0>>a1>>a2>>a3; init();
while(T--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 25ms
memory: 9272kb
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: 25ms
memory: 9172kb
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: 9220kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 50ms
memory: 9100kb
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:
48 48 51 46 61 54 78 54 66 67 51 75 43 46 62 48 46 56 51 66 59 58 62 54 42 53 43 55 49 55 48 65 55 64 67 59 72 45 60 48 53 59 56 56 75 50 64 61 65 59 54 49 61 74 60 72 71 57 78 50 62 61 47 46 53 67 50 54 68 71 45 46 49 48 51 62 54 71 53 53 59 66 58 51 45 50 58 65 43 51 63 71 62 65 53 44 52 62 58 47 ...
result:
wrong answer 1st numbers differ - expected: '34', found: '48'