QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#384693 | #5874. Mystery Square | Kevin5307 | 10 | 63ms | 3536kb | C++23 | 2.6kb | 2024-04-10 10:30:41 | 2024-04-10 10:30:42 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
for(int tc=1;tc<=t;tc++)
{
string s;
cin>>s;
int m=sz(s);
int cnt0=0,cnt1=0;
for(int i=0;i<m;i++)
if(s[i]=='?')
{
if(i<m/2)
cnt0++;
else
cnt1++;
}
if(cnt0<=cnt1)
{
bool flag=0;
for(int i=0;i<(1<<cnt0)&&!flag;i++)
{
longer mnval=0,mxval=0;
int c=0;
for(int j=0;j<m;j++)
{
mnval<<=1;
mxval<<=1;
if(s[j]!='?')
{
mnval|=(s[j]&1);
mxval|=(s[j]&1);
}
else if(c<cnt0)
{
mnval|=(i>>c&1);
mxval|=(i>>c&1);
c++;
}
else
mxval|=1;
}
longer a=sqrt((long double)mnval),b=sqrt((long double)mxval);
for(longer x=a;x<=b&&!flag;x++)
{
longer val=x*x;
if((val&mnval)==mnval)
{
longer diff=mnval^val;
longer tmp=mnval^mxval;
if((diff&tmp)==diff)
{
flag=1;
cout<<"Case #"<<tc<<": ";
for(int i=m-1;i>=0;i--)
cout<<(int)(val>>i&1);
cout<<'\n';
}
}
}
}
}
else
{
bool flag=0;
for(int i=0;i<(1<<cnt0)&&!flag;i++)
{
longer mnval=0,mxval=0;
int c=0;
for(int j=0;j<m;j++)
{
mnval<<=1;
mxval<<=1;
if(s[j]!='?')
{
mnval|=(s[j]&1);
mxval|=(s[j]&1);
}
else if(c<cnt0)
{
mnval|=(i>>c&1);
mxval|=(i>>c&1);
c++;
}
else
mxval|=1;
}
longer a=sqrt((long double)mnval),b=sqrt((long double)mxval);
for(longer x=a;x<=b&&!flag;x++)
{
longer val=x*x;
if((val&mnval)==mnval)
{
longer diff=mnval^val;
longer tmp=mnval^mxval;
if((diff&tmp)==diff)
{
flag=1;
cout<<"Case #"<<tc<<": ";
for(int i=m-1;i>=0;i--)
cout<<(int)(val>>i&1);
cout<<'\n';
}
}
}
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 63ms
memory: 3536kb
input:
25 1??? 1 10??110??00??1000?? 1??010?0110?1010?0?010?0111011?11100?100010?0??0??1 1??11????00??1?1?0?1??01??110110?11?00100110?00100?0?00 11?1?1???11111?11?1??11110000?00?????00??0?000?000?1 10??000000?0?00000?00000000??0?0000???00??????0000??? 101???11??11000?????1??1?1??10??0?0100011?0001?01011001...
output:
Case #1: 1001 Case #2: 1 Case #3: 1011110110000100001 Case #4: 111010001100101000001010111011011100110001000110001 Case #5: 1101111110000101100101010111011001110010011000010000100 Case #6: 1111111111111111111111111000000000000000000000000001 Case #7: 1000000000000000000000000000000000000000000000000...
result:
ok 25 lines
Subtask #2:
score: 0
Time Limit Exceeded
Test #2:
score: 0
Time Limit Exceeded
input:
25 1????????????????????111101010000011100110101111000001011111100110000011000101100000010010110100101000???????????????????? 10?11100?000111??11?01010110100??1?100111?001000000??0101?110?0111?011?11?1??00010111?010??100?100??10?010?001001110111110?1 1000100111100100110011010111100001111010?????????...