QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#779959 | #9802. Light Up the Grid | YgkingNan | WA | 64ms | 13936kb | C++23 | 2.9kb | 2024-11-24 23:07:13 | 2024-11-29 22:50:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll T,a1,a2,a3,a4,n;
ll dp[80005],jll[80005];
bitset<4>bs;
bitset<16>back[80005];
struct node
{
ll data;
bitset<16>status;
bitset<16>back;
ll ansp;
bool operator< (const node& x)const
{
return data>x.data;
}
};
bool vis[80005];
priority_queue<node>que;
std::vector<bitset<4>> all_toggle
{
0b1000,0b0100,0b0010,0b0001,
0b1100,0b0011, //a2
0b1010,0b0101, //a3
0b1111 //a4
};
inline void init()
{
{
struct node temp;
temp.status[15]=1;
temp.data=0;
que.push(temp);
}
while(!que.empty())
{
auto temp=que.top();
que.pop();
//cout<<temp.data<<" "<<temp.status<<endl;
//cout<<"======"<<endl;
if(!vis[temp.status.to_ullong()])
{
vis[temp.status.to_ullong()]=true;
dp[temp.status.to_ullong()]=temp.data;
back[temp.status.to_ullong()]=temp.back;
jll[temp.status.to_ullong()]=temp.ansp;
for(int i=0;i<=8;i++)
{
struct node tep;
tep.status=0;
tep.data=temp.data;
tep.back=temp.status;
tep.ansp=i;
for(int j=0;j<=14;j++)
{
int xpp;
if(temp.status[j]==1)
{
xpp=j;
xpp^=(all_toggle[i].to_ullong());
tep.status[xpp]=1;
}
}
if(i<=3) tep.data+=a1;
else if(i>3 && i<=5) tep.data+=a2;
else if(i>5 && i<=7) tep.data+=a3;
else tep.data+=a4;
tep.status[15]=0;
if(!vis[tep.status.to_ullong()])
que.push(tep);
tep.status[15^(all_toggle[i].to_ullong())]=1;
if(!vis[tep.status.to_ullong()])
que.push(tep);
}
}
}
}
inline void solve()
{
cin>>T>>a1>>a2>>a3>>a4;
init();
while(T--)
{
cin>>n;
//cout<<"Yes"<<endl;
bitset<16>ans;
ans=0;
for(int i=1;i<=n;i++)
{
int tp=0;
std::string s;
cin>>s;
bs[3]=s[0]=='1';
bs[2]=s[1]=='1';
cin>>s;
bs[1]=s[0]=='1';
bs[0]=s[1]=='1';
//cout<<bs<<endl;
ans[bs.to_ullong()]=1;
}
ans[15]=0;
//cout<<ans<<endl;
if(ans==0) cout<<min(a1,min(a2,min(a3,a4)))*2<<endl;
else if(dp[ans.to_ullong()]==0) cout<<min(a1,min(a2,min(a3,a4)))*2<<endl;
else cout<<dp[ans.to_ullong()]<<endl;
//cout<<"======"<<endl;
ll bb=ans.to_ullong();
ll sum=0;
//while(sum<=100)
//{
// sum++;
// cout<<back[bb]<<" "<<jll[bb]<<endl;
// bb=back[bb].to_ullong();
//}
}
}
int main()
{
//ios::sync_with_stdio(false);
//cin.tie(nullptr),cout.tie(nullptr);
ll T=1;
//cin>>T;
while(T--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 42ms
memory: 13232kb
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: 28ms
memory: 9372kb
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: 28ms
memory: 8936kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 64ms
memory: 13936kb
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:
32 30 34 34 40 36 41 38 40 37 34 42 34 37 37 31 29 35 39 40 38 36 40 34 25 34 34 38 34 31 32 37 34 36 37 40 40 34 37 34 29 35 35 36 42 35 35 34 38 34 37 29 38 38 36 37 43 36 41 30 40 39 33 33 34 36 34 34 42 40 34 32 28 34 32 37 34 39 34 37 32 36 30 30 32 34 38 40 34 36 40 39 34 36 34 25 36 40 36 34 ...
result:
wrong answer 1st numbers differ - expected: '34', found: '32'