QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#810846 | #9802. Light Up the Grid | yeVegeTable | WA | 44ms | 39460kb | C++20 | 2.7kb | 2024-12-12 12:04:02 | 2024-12-12 12:04:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[1202020],b[1202020],p[1202020],vis[1202020];
vector<pair<int,int>>g[22];
int dis[22][22];
int dp[101000][44];
string s[2020];
int res[101010];
int f(int x){
int res=0;
while(x)res+=x&1,x>>=1;
return res;
}
int f(string s){
int res=0;
for(int i=0;i<4;i++)res^=(1<<i)*(1-(s[i]-'0'));
return res;
}
vector<int>gg[17];
signed main(){
// int t=1;
// for(int i=1;i<=16;i++)t*=i;
// cout<<t<<'\n';
ios::sync_with_stdio(false);
cin.tie(0);
int _=1,i,j,k;
int a0,a1,a2,a3;
cin>>_>>a0>>a1>>a2>>a3;
for(i=0;i<=15;i++){
for(j=0;j<4;j++){
g[i].push_back({i^(1<<j),a0});
}
// if(i==0)cout<<(i^(1<<0)^(1<<2))<<'\n';
g[i].push_back({i^(1<<0)^(1<<1),a1});
g[i].push_back({i^(1<<2)^(1<<3),a1});
g[i].push_back({i^(1<<0)^(1<<2),a2});
g[i].push_back({i^(1<<1)^(1<<3),a2});
g[i].push_back({i^15,a3});
}
memset(dp,0x3f,sizeof(dp));
memset(dis,0x3f,sizeof(dis));
for(i=0;i<16;i++){
dis[i][i]=0;
for(auto &[x,y]:g[i])dis[i][x]=dis[x][i]=y;
}
// dp[0][0]=0;
// for()
for(i=0;i<=15;i++){
for(j=0;j<=15;j++){
for(k=0;k<=15;k++){
dis[j][k]=min(dis[j][k],dis[j][i]+dis[i][k]);
}
}
}
// for(i=0;i<16;i++){
// for(j=0;j<16;j++)cout<<dis[i][j]<<" ";
// cout<<'\n';
// }
for(i=0;i<65536;i++){
gg[f(i)].push_back(i);
}
// sort(b,b+65536,cmp);
dp[1][0]=min({a0,a1,a2,a3})*2;
for(i=1;i<=15;i++){
dp[1<<i][i]=dis[0][i];
}
for(i=2;i<=15;i++){
for(auto j:gg[i]){
for(k=0;k<=15;k++){
if(j>>k&1){
for(int z=0;z<=15;z++){
if(z==k)continue;
if(j>>z&1)dp[j][k]=min(dp[j][k],dp[j^(1<<k)][z]+dis[z][k]);
}
// if(i==2&&j==6)cout<<j<<" "<<k<<" "<<dp[j][k]<<'\n';
}
}
}
}
while(_--){
int k,n,j,m,d,i,x;
cin>>n;
int st=0;
string s;
for(i=0;i<n;i++){
cin>>s;
string t;
cin>>t;
s+=t;
st^=1<<f(s);
}
if(n==1&&s=="1111"){
cout<<min({a0,a1,a2,a3})*2<<'\n';
continue;
}
int mi=1e9;
for(i=0;i<=15;i++){
mi=min(mi,dp[st][i]);
}
cout<<mi<<'\n';
}
}
/*
dd
1 10000 100 10 10000
1
10
01
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 34ms
memory: 39168kb
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: 39460kb
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: 33ms
memory: 38800kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: 0
Accepted
time: 36ms
memory: 39212kb
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:
34 32 36 36 40 36 42 38 40 41 36 44 34 37 37 32 29 39 39 40 38 39 44 37 29 37 37 38 34 34 32 41 34 36 41 40 44 34 37 34 29 36 39 40 42 35 39 37 38 38 41 29 40 41 36 41 43 40 41 34 42 39 37 33 34 38 38 37 42 40 34 36 28 34 32 38 36 39 38 37 36 38 34 34 34 34 42 40 38 38 40 40 37 40 38 29 36 40 36 34 ...
result:
ok 10000 numbers
Test #5:
score: 0
Accepted
time: 35ms
memory: 38900kb
input:
10000 73 78 73 17 11 01 10 01 11 10 00 11 11 00 00 11 01 10 11 11 10 00 11 10 01 01 00 6 00 00 10 11 11 10 01 01 11 01 11 00 7 01 11 01 00 10 00 10 11 10 10 00 00 01 01 10 10 01 10 10 00 10 10 11 10 00 01 01 01 10 11 11 11 00 00 01 10 11 11 01 11 10 10 01 01 00 01 ...
output:
523 382 287 579 523 596 343 275 343 472 382 343 455 326 433 360 579 545 506 523 326 528 467 382 438 421 377 460 416 579 489 596 309 326 326 596 438 387 506 562 523 377 416 309 523 348 365 343 416 392 343 399 348 506 421 596 450 426 579 370 506 185 489 377 489 387 416 472 314 489 506 450 421 433 416 ...
result:
ok 10000 numbers
Test #6:
score: 0
Accepted
time: 32ms
memory: 38752kb
input:
10000 701 328 455 703 7 10 11 00 01 00 11 00 10 01 00 11 11 11 00 7 00 01 01 00 00 11 11 11 00 00 11 10 11 01 6 01 10 01 01 00 01 00 11 10 01 11 00 8 00 11 10 11 00 10 00 01 11 10 01 01 10 10 11 00 5 00 11 10 11 11 00 01 10 01 00 7 00 01 10 10 11 01 00 10 10 00 11 11...
output:
3124 3124 2595 4153 2595 3177 3907 2796 4235 3833 3296 2595 4809 3579 3579 3050 3169 3907 3907 3251 3169 2714 2595 3050 3251 3542 2796 3251 4563 3251 3452 3907 3251 3251 4034 4034 1730 2140 3087 4153 3907 3907 4727 4809 2923 3497 3579 3431 3251 4235 2267 4354 2595 4153 3169 4727 3087 4235 3579 2595 ...
result:
ok 10000 numbers
Test #7:
score: -100
Wrong Answer
time: 44ms
memory: 38740kb
input:
10000 6459 225 8979 7226 16 00 11 11 01 10 01 10 10 00 01 01 11 11 00 11 11 00 10 11 10 01 01 01 00 01 10 10 00 00 00 10 11 16 10 00 11 10 01 10 11 11 00 01 00 00 01 00 01 11 01 01 10 01 00 10 10 10 00 11 11 01 10 11 11 00 16 10 11 01 11 10 00 10 10 01 00 11 11 01...
output:
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100...
result:
wrong answer 1st numbers differ - expected: '22302', found: '1000000000'