QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#405715#5874. Mystery Squarecyb10100 0ms0kbC++142.5kb2024-05-06 12:54:192024-05-06 12:54:21

Judging History

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

  • [2024-05-06 12:54:21]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-05-06 12:54:19]
  • 提交

answer

/**
 * @author : cyb1010
 * @date   : 2024-05-06 10:23:57
 * @file   : grow.cpp
 */
#include <bits/stdc++.h>
using namespace std;
#define fo(s) freopen(s ".in", "r", stdin), freopen(s ".out", "w", stdout)
#define fi first
#define se second
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef __uint128_t U;
U val, msk, UP;
int __, n, g[60], tot, N, A;
char s[130];
bool perf1(U dw) {
    U l = sqrtl(dw), x;
    while ((x = l * l) <= UP) {
        if ((x ^ dw) & msk) {
            l++;
            continue;
        }
        for (int i = n - 1; ~i; i--) putchar((x >> i & 1) + '0');
        while (A--) putchar('0');
        putchar('\n');
        return true;
    }
    return false;
}
bool perf2() {
    U T = s[n - 1] - '0', x = 0, M = 0;
    for (int i = 1; i < N; i++) {
        T |= (s[n - i - 1] - '0') << i, M = M << 1 | 1;
        if (((x * x) ^ T) & M) x += (U)1 << (i - 1);
    }
    x += (U)1 << N - 1;
    x *= x;
    if ((x ^ val) & msk) return false;
    for (int i = n - 1; ~i; i--) putchar((x >> i & 1) + '0');
    while (A--) putchar('0');
    putchar('\n');
    return true;
}
void work() {
    scanf("%s", s), n = strlen(s), A = 0;
    while (s[n - 1] == '0') n -= 2, A += 2;
    while (n >= 1) {
        s[n - 1] = '1';
        N = (n + 1) / 2, tot = 0;
        msk = val = UP = 0;
        for (int i = 0; i < n; i++) {
            msk <<= 1, val <<= 1, UP <<= 1;
            if (s[i] == '?')
                g[tot++] = i, UP |= 1;
            else
                msk |= 1, val |= (s[i] - '0'), UP |= (s[i] - '0');
        }
        if (!tot) {
            printf("%s", s);
            while (A--) putchar('0');
            putchar('\n');
            return;
        }
        int cnt = (tot + 1) / 2;
        if (g[cnt] >= N) {
            int M = 1 << cnt;
            for (int i = 0; i < M; i++) {
                U tmp = val;
                for (int j = 0; j < cnt; j++) tmp |= (i >> j & 1) << g[j];
                if (perf1(tmp)) return;
            }
        } else {
            int M = 1 << cnt;
            for (int i = 0; i < M; i++) {
                for (int j = 0; j < cnt; j++)
                    s[g[tot - j - 1]] = '0' + (i >> j & 1);
                if (perf2()) return;
            }
        }
        n -= 2, A += 2;
    }
    assert(0);
}
int main() {
    // fo("grow");
    // work();
    int _;
    scanf("%d", &_);
    for (int i = 1; i <= 10; i++) printf("Case #%d: ", i), work();
    return 0 ^ __ ^ 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: