QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#797595 | #9802. Light Up the Grid | AiriS# | TL | 15ms | 3664kb | C++14 | 1.5kb | 2024-12-03 14:37:24 | 2024-12-03 14:37:25 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int mask[9]={8,4,2,1,12,3,10,5,15};
typedef long long ll;
template<typename T>void read(T &x){
x=0;char c=getchar();bool f=false;
while(c<'0'||c>'9'){if(c=='-')f=true;c=getchar();}
while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
if(f) x=-x;
}
int a0,a1,a2,a3;
int calc(int x)
{
assert(x>=0&&x<=8);
if(x<4)return a0;
if(x<6)return a1;
if(x<8)return a2;
return a3;
}
int m,tar,res;
vector<int>v;
void dfs(int k,int cost,int ok)
{
if(ok==tar)res=min(res,cost);
for(int i=0;i<9;i++)
{
if((k>>i)&1)continue;
for(int j=0;j<m;j++)
{
v[j]^=mask[i];
if(v[j]==15)ok^=(1<<j);
}
dfs(k|(1<<i),cost+calc(i),ok);
for(int j=0;j<m;j++)
{
if(v[j]==15)ok^=(1<<j);
v[j]^=mask[i];
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int T;
cin>>T>>a0>>a1>>a2>>a3;
while(T--)
{
cin>>m;
v.clear();
for(int i=0;i<m;i++)
{
int s1,s2;
cin>>s1>>s2;
v.push_back(s1/10*8+s1%10*4+s2/10*2+s2%10);
}
if(m==1&&v[0]==15)
{
res=min({a0,a1,a2,a3})*2;
cout<<res<<endl;
continue;
}
tar=(1<<m)-1,res=1e9;
dfs(0,0,0);
cout<<res<<endl;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 15ms
memory: 3664kb
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: 9ms
memory: 3616kb
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: 0ms
memory: 3652kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Time Limit Exceeded
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:
58 58 58 58 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 58 1000000000 1000000000 1000000000 1000000000 58 1000000000 58 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 50 58 58 1000000000 50 1000000000 50 1000000000 58 1000000000 1000000000 1000000000 10000000...