QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#405587 | #5874. Mystery Square | cmk666 | 41 ✓ | 427ms | 3704kb | C++23 | 1.9kb | 2024-05-06 08:30:21 | 2024-05-06 08:30:23 |
Judging History
answer
#pragma GCC optimize("Ofast", "unroll-loops")
#include<bits/stdc++.h>
using namespace std; using ll = long long;
#define For(i, j, k) for ( int i = (j) ; i <= (k) ; i++ )
#define Fol(i, j, k) for ( int i = (j) ; i >= (k) ; i-- )
int n, z, md, l, r; string s; __int128 msk, nd; bool fnd;
inline void chk(__int128 x)
{
if ( fnd || ( ( x *= x ) & msk ) != nd ) return;
Fol(i, n - 1, 0) cout << (int)( ( x >> i ) & 1 ); while ( z-- ) cout << 0; cout << '\n', fnd = true;
}
inline void dfsl(int u, __int128 v, __int128 o)
{
if ( fnd ) return;
if ( u == md ) { chk(o), chk(o | ( (__int128)1 << ( u - 1 ) )); return; }
int nx = ( ( o * o ) >> u ) & 1;
if ( s[u] == '?' || s[u] == '0' + nx ) dfsl(u + 1, v | ( (__int128)nx << u ), o);
if ( u != 2 ) nx = !nx;
if ( s[u] == '?' || s[u] == '0' + nx ) dfsl(u + 1, v | ( (__int128)nx << u ), o | ( (__int128)1 << ( u - 1 ) ));
}
inline void dfsr(int u, __int128 v)
{
if ( fnd ) return;
if ( u == md - 1 )
{
__int128 o = sqrtl(v);
while ( o * o < v ) o++;
while ( ( ( (__int128)o * o ) >> md ) == ( v >> md ) ) chk(o++);
return;
}
if ( s[u] == '?' || s[u] == '0' ) dfsr(u - 1, v);
if ( s[u] == '?' || s[u] == '1' ) dfsr(u - 1, v | ( (__int128)1 << u ));
}
inline void work()
{
static int _; cout << "Case #" << ++_ << ": ";
z = 0, fnd = false, cin >> s, reverse(s.begin(), s.end());
for ( ; s.size() ; s.erase(0, 2), z += 2 ) if ( s[0] == '?' || s[0] == '1' )
{
n = (int)s.size(), s[0] = '1', md = ( n + 1 ) >> 1, msk = nd = 0;
For(i, 0, n - 1) if ( s[i] != '?' ) msk |= (__int128)1 << i, nd |= (__int128)( s[i] - '0' ) << i;
if ( count(s.begin(), s.begin() + md, '?') < count(s.begin() + md, s.end(), '?') ) dfsl(2, 1, 1);
else dfsr(n - 1, 0);
if ( fnd ) return;
}
assert(false);
}
int main()
{
cin.tie(nullptr) -> sync_with_stdio(false);
int t; cin >> t; while ( t-- ) work(); return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 1ms
memory: 3704kb
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: 427ms
memory: 3704kb
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