QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#799656 | #9802. Light Up the Grid | xh_team# | WA | 16ms | 12388kb | C++20 | 1.6kb | 2024-12-05 16:52:13 | 2024-12-05 16:52:14 |
Judging History
answer
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using i64=long long;
#define int ll
const int N=2e5+10,mod=1e9+7;
ll qpow(ll a,ll b,ll p){ll res=1;for(;b;b>>=1,a=a*a%p)if(b&1)res=res*a%p;return res;}
int dx[4]={-1,1,0,0},dy[4]={0,0,-1,1};
int dis[16][16];
int n,a0,a1,a2,a3;
int st[1<<16][16];
int ans[1<<16];
void init(){
memset(dis,0x3f,sizeof dis);
for(int i=0;i<16;i++){
dis[i][i^1]=dis[i][i^2]=dis[i][i^4]=dis[i][i^8]=a0;
dis[i][i^3]=dis[i][i^15]=a1;
dis[i][i^5]=dis[i][i^10]=a2;
dis[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++){
dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
}
memset(st,0x3f,sizeof st);
st[0][15]=0;
int inf=st[0][0];
for(int i=0;i<1<<16;i++){
ans[i]=inf;
for(int x=0;x<16;x++)
if(st[i][x]!=inf){
for(int y=0;y<16;y++){
st[i|(1<<y)][y]=min(st[i|(1<<y)][y],st[i][x]+dis[x][y]);
}
}
}
for(int i=0;i<1<<16;i++){
for(int x=0;x<16;x++){
ans[i]=min(ans[i],st[i][x]);
}
}
}
void solve(){
cin>>n;
int res=0;
for(int i=1,x,y;i<=n;i++){
cin>>x>>y;
int w=1*(x/10)+2*(x%10)+4*(y/10)+8*(y%10);
res|=1<<w;
}
//cout<<res<<"\n";
cout<<ans[res]<<"\n";
}
signed main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int _=1;
cin>>_;
cin>>a0>>a1>>a2>>a3;
init();
while(_--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 12ms
memory: 12384kb
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: 7ms
memory: 12372kb
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: 8ms
memory: 12388kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 16ms
memory: 12316kb
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:
44 50 49 51 54 52 62 47 53 61 44 59 44 50 47 42 45 51 52 58 50 54 63 58 44 46 51 51 48 50 43 60 44 57 56 56 63 47 47 49 46 47 48 54 61 45 53 58 56 52 59 44 60 61 50 61 62 50 60 39 56 56 52 43 48 48 52 52 61 58 45 45 44 39 43 52 46 58 46 52 56 60 49 50 46 47 54 59 49 49 57 55 53 55 53 47 44 57 54 45 ...
result:
wrong answer 1st numbers differ - expected: '34', found: '44'