QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#405758#5874. Mystery Squarezjy00010 0ms0kbC++171.7kb2024-05-06 13:10:052024-05-06 13:10:05

Judging History

你现在查看的是最新测评结果

  • [2024-05-06 13:10:05]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-05-06 13:10:05]
  • 提交

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){
        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,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(;(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: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

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:


result:


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?????????...

output:


result: