QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#405824 | #5874. Mystery Square | lzytag | 0 | 94ms | 3556kb | C++14 | 2.8kb | 2024-05-06 14:07:11 | 2024-05-06 14:07:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef __int128 lll;
typedef long long ll;
const lll I = 1;
string str;
int a[130];
int n,m;
bool flag = 0;
void check1(lll x)
{
if(flag) return ;
int mid = (1+m)/2;
lll cur = 1;
for(int j = 1;j < mid-1;j++)
{
lll X = cur*cur;
if((X^x) & (I<<(j+1))) cur |= I<<j;
}
cur |= I<<(mid-1);
lll X = cur*cur;
for(int i = 1;i <= m;i++)
{
int b = X>>(i-1)&1;
if((b^a[i]) == 1) return ;
}
for(int i = m;i > 0;i--)
{
int b = X>>(i-1)&1;
cout<<b;
}
for(int i = 1;i <= n-m;i++) cout<<0;
cout<<"\n";
flag = 1;
//exit(0);
}
void check2(lll x)
{
if(flag) return ;
int mid = (1+m)/2;
lll cur = ceil(sqrtl(x));
lll X = cur*cur;
for(int i = 1;i <= m;i++)
{
int b = X>>(i-1)&1;
if((b^a[i]) == 1) return ;
}
for(int i = m;i > 0;i--)
{
int b = X>>(i-1)&1;
cout<<b;
}
for(int i = 1;i <= n-m;i++) cout<<0;
cout<<"\n";flag = 1;
//exit(0);
}
void sou1(int x,lll y)
{
if(x == (m+1)/2+1) return check1(y),void();
if(a[x] != 0 && x != 2) sou1(x+1,y|(I<<(x-1)));
if(a[x] != 1 && x != 1) sou1(x+1,y);
}
void sou2(int x,lll y)
{
if(x == m+1) return check2(y),void();
if(a[x] != 0 && x != 2) sou2(x+1,y|(I<<(x-1)));
if(a[x] != 1 && x != 1) sou2(x+1,y);
}
void work()
{
int mid = (m+1)/2,cnt1 = 0,cnt2 = 0;
for(int i = 1;i <= mid;i++)
if(a[i] == 2) cnt1++;
for(int i = mid+1;i <= m;i++)
if(a[i] == 2) cnt2++;
//cout<<cnt1<<" "<<cnt2<<"\n";
//for(int i = 1;i <= m;i++) cout<<a[i]<<" ";
//cout<<"\n";
if(cnt1 < cnt2) sou1(1,0);
else sou2(mid+1,0);
}
int TT;
int solve()
{
//system("fc grow1.out grow.out");
//freopen("grow.in","r",stdin);
//freopen("grow.out","w",stdout);
flag = 0;
++TT;cin>>str;n = str.size();
if(TT < 16) return 0;
cout<<"Case #"<<TT<<": ";
cout<<str<<"\n";
for(int i = 1;i <= n;i+=2)
{
if(str[n-i] == '0') continue;
bool Flag = 0;
for(int j = 1;j < i;j++) if(str[n-j] == '1') Flag = 1;
if(Flag) continue;
m = n-i+1;
for(int j = 1;j <= m;j++)
{
if(str[m-j] == '?') a[j] = 2;
else a[j] = str[m-j]-'0';
}
if(m == 2) continue;
if(m == 1)
{
if(flag) continue;
cout<<1;
for(int j = 1;j < n;j++) cout<<0;
cout<<"\n";flag = 1;
continue;
}
work();
}
return 0;
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);
int T;cin>>T;
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3556kb
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 #16: 110?0?01????11?0?111?1???1??0?1?0011??01010100?110?1000000 Case #17: 100?01?111111111?1?101101011?100100?0?00001?10111?0?1000000 10000101111111110111011010110100100100000010101111001000000 Case #18: 1001?111?10?10??00?111????010100?????10111???0001??001 100111110101100100111100100101000000...
result:
wrong answer 1st lines differ - expected: 'Case #1: 1001', found: 'Case #16: 110?0?01????11?0?111...?0?1?0011??01010100?110?1000000'
Subtask #2:
score: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 94ms
memory: 3508kb
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?????????...
output:
Case #16: 11?00001100011??0001000?11?11?0?111011011000100?1?101011?1?11?00011?00?1010001?0?101010010101?00?100?0?011101101001?0000000 110000011000111000010001110111011110110110001001111010110101100001110001010001101101010010101100010010101110110100100000000 Case #17: 10011000000010000111010111100011...
result:
wrong answer 1st lines differ - expected: 'Case #1: 111001011101010101101...1010010100001101011000010100001', found: 'Case #16: 11?00001100011??0001...1?00?100?0?011101101001?0000000'