QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#779956 | #9802. Light Up the Grid | YgkingNan | WA | 35ms | 13656kb | C++23 | 2.9kb | 2024-11-24 23:04:57 | 2024-11-24 23:04:58 |
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(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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 35ms
memory: 13656kb
input:
2 1000 100 10 1 4 10 00 01 00 00 10 00 01 1 11 11
output:
1121 1
result:
wrong answer 2nd numbers differ - expected: '2', found: '1'