QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#864739 | #9802. Light Up the Grid | Cocoder | WA | 23ms | 13952kb | C++14 | 2.1kb | 2025-01-20 22:33:19 | 2025-01-20 22:33:19 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define inf 1e15
#define endl '\n'
using namespace std;
const int N=20,M=70010;
ll a0,a1,a2,a3;
ll cost[N];
ll dis[N][N],dp[M][N];
void Floyd()
{
for(int k=0;k<=15;k++)
{
for(int i=0;i<=15;i++)
for(int j=0;j<=15;j++)
{
dis[j][i]=dis[i][j]=min(dis[i][k]+dis[k][j],dis[i][j]);
}
}
return ;
}
ll dfs(int sta,int v)
{
if(sta==1) return 0;
if(dp[sta][v]) return dp[sta][v];
int s=sta-(1<<v);
if(s==1) return dis[0][v];
ll ret=inf;
for(int i=1;i<=15;i++)
{
if(s&(1<<i)) ret=min(ret,dfs(s,i)+dis[i][v]);
}
return dp[sta][v]=ret;
}
void init()
{
cin>>a0>>a1>>a2>>a3;
cost[1]=cost[2]=cost[4]=cost[8]=a0;
cost[3]=cost[12]=a1;
cost[5]=cost[10]=a2;
cost[15]=a3;
for(int i=0;i<=15;i++)
for(int j=0;j<=15;j++)
if(i==j) dis[i][j]=0;
else dis[i][j]=inf;
for(int i=0;i<=15;i++)
{
for(int j=i+1;j<=15;j++)
if(cost[i^j]>0) dis[j][i]=dis[i][j]=cost[i^j];
}
Floyd();
for(int i=1;i<=(1<<16)-1;i+=2)
for(int j=1;j<=15;j++)
{
if(i&(1<<j)) dp[i][j]=dfs(i,j);
//if(i<=100) cout<<i<<' '<<j<<':'<<dp[i][j]<<endl;
}
return ;
}
void solve()
{
int m;
cin>>m;
int res=0,add=0;
for(int i=1;i<=m;i++)
{
int tmp=8,v=0;
for(int j=1;j<=4;j++)
{
char c;
cin>>c;
int x=c-'0';
if(x==0) v+=tmp;
tmp/=2;
}
res|=1<<v;
}
if(res&1) add=2*a3;
if(res==1)
{
cout<<add<<endl;
return ;
}
res|=1;
ll ans=inf;
for(int i=1;i<=15;i++)
if(res&(1<<i))
ans=min(ans,dp[res][i]);
cout<<ans+add<<endl;
return ;
}
signed main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int o=1;
cin>>o;
init();
while(o--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 12ms
memory: 13952kb
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: 15ms
memory: 13824kb
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: 15ms
memory: 13952kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 23ms
memory: 13952kb
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 46 50 50 56 36 57 38 40 53 50 58 34 37 37 47 29 51 39 40 38 52 56 50 41 50 50 38 34 47 32 53 50 52 53 56 56 34 37 34 29 51 51 52 58 35 51 50 38 50 53 29 54 54 36 53 43 52 41 46 56 39 49 49 34 52 50 50 42 40 50 48 28 34 32 53 50 39 50 37 48 52 46 46 48 34 54 40 50 52 40 55 50 52 50 41 36 40 36 34 ...
result:
wrong answer 1st numbers differ - expected: '34', found: '48'