QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#405768 | #5874. Mystery Square | zjy0001 | 41 ✓ | 423ms | 3756kb | C++17 | 1.7kb | 2024-05-06 13:23:08 | 2024-05-06 13:23:11 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long
using namespace std;
inline LLL solveL(int R,LLL X,LLL Y){
const LLL Q=(Y-X)>>((R+1)/2)<<((R+1)/2);
for(LLL S=Q;;(--S)&=Q){
const LLL l=X|S,r=l+((LLL)1<<((R+1)/2));
for(LLL Z=sqrtl(l);Z*Z<=r;++Z){
const LLL Q=Z*Z;
if((X&Q)==X&&(Y&Q)==Q)return Z;
}
if(!S)break;
}
return 0;
}
inline LLL solveR(int R,LLL X,LLL Y,int r,LLL Z){
if(r==(R+1)/2){
const LLL Q=Z*Z;
if((X&Q)==X&&(Y&Q)==Q)return Z;
else return 0;
}
if(r==1||r==(R+1)/2-1||((Y-X)>>(r+1)&1)){
const LLL Q=solveR(R,X,Y,r+1,Z);
return Q?Q:solveR(R,X,Y,r+1,((LLL)1<<r)|Z);
}
return solveR(R,X,Y,r+1,((X^(Z*Z))>>(r+1)&1)<<r|Z);
}
inline LLL solve(LLL X,LLL Y){
int R=0;for(;((LLL)1<<R)<=X;++R);
const int cl=__builtin_popcountll((Y-X)>>((R+1)/2));
const int cr=__builtin_popcountll((Y-X)&(((LLL)1<<((R+1)/2))-1));
if(cl<cr)return solveL(R,X,Y);else return solveR(R,X,Y,1,1);
}
inline void MAIN(){
string s;int n;
cin>>s,n=s.length();
LLL X=0,Y=0;
for(int i=0;i<n;++i){
X*=2,Y*=2;
if(s[i]=='1')++X;
if(s[i]!='0')++Y;
}
LLL Z=0;
for(int i=0;Y>>i;i+=2){
const auto z=solve(X>>i,Y>>i);
if(z){Z=(z*z)<<i;break;}
}
s="";
while(Z)s.push_back('0'+(Z&1)),Z>>=1;
reverse(s.begin(),s.end());
cout<<s<<'\n';
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
int t=1;cin>>t;for(int i=1;t--;++i)cout<<"Case #"<<i<<": ",MAIN();
return 0;
}
/*
*/
详细
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 1ms
memory: 3700kb
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: 31
Accepted
Test #2:
score: 31
Accepted
time: 423ms
memory: 3756kb
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 #1: 11100101110101010110111110101000001110011010111100000101111110011000001100010110000001001011010010100001101011000010100001 Case #2: 1011110000001110111001010110100001110011100010000001101010110001111011111110000010111101010100010010101010100100111011111001 Case #3: 1000100111100100110011010...
result:
ok 25 lines
Extra Test:
score: 0
Extra Test Passed