QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#121447#5874. Mystery Squarewhatever0 173ms3548kbC++172.1kb2023-07-08 09:27:432023-07-08 09:27:46

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-08 09:27:46]
  • 评测
  • 测评结果:0
  • 用时:173ms
  • 内存:3548kb
  • [2023-07-08 09:27:43]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
int rng(int l, int r) { return rnd() % (r - l + 1) + l; }
#define rep(i, a, b) for (int i = (a), I = (b); i <= I; ++i)
#define per(i, a, b) for (int i = (a), I = (b); i >= I; --i)
using i128 = __int128_t;
template<typename T> void up(T &x, T y) { if (x < y) x = y; }
template<typename T> void down(T &x, T y) { if (x > y) x = y; }

string s;
int n, m;
i128 ans;

bool match(int x, int y) {
    return s[x] == '?' || s[x] == '0' + y;
}
void check(i128 x) {
    x *= x;
    rep(i, 0, n - 1) if (!match(i, x >> i & 1)) return;
    ans = x;
}

void dfs(int pos, i128 cur) {
    if (~ans) return;
    if (pos == m - 1) {
        i128 p = 0;
        per(i, m, 0) {
            i128 q = p | i128(1) << i;
            if (q * q <= cur) p = q;
        }
        while (p * p < cur) ++p;
        while (((p * p) >> m) == (cur >> m)) check(p), ++p;
        return;
    }
    if (match(pos, 0)) dfs(pos - 1, cur);
    if (match(pos, 1)) dfs(pos - 1, cur | i128(1) << pos);
}

void dfs(int pos, i128 cur, i128 sqr) {
    if (~ans) return;
    if (pos == m) {
        check(cur);
        check(cur | i128(1) << (pos - 1));
        return;
    }
    int tmp = (sqr * sqr) >> pos & 1;
    rep(k, 0, 1) {
        int val = tmp + k * (sqr & 1);
        if (pos == 2) val += k;
        if (match(pos, val & 1)) dfs(pos + 1, cur | i128(val) << pos, sqr | i128(k) << (pos - 1));
    }
}

void solve() {
    cin >> s;
    n = s.size();
    reverse(s.begin(), s.end());
    m = (n + 1) / 2;
    int cnt_left = count(s.begin(), s.end() + m, '?');
    int cnt_right = count(s.begin() + m, s.end(), '?');
    ans = -1;

    if (cnt_left < cnt_right) {
        if (match(0, 0)) dfs(2, 0, 0);
        if (match(0, 1)) dfs(2, 1, 1);
    } else {
        dfs(n - 1, 0);
    }
    per(i, n - 1, 0) cout << int(ans >> i & 1);
    cout << "\n";
}

int main() {
    ios::sync_with_stdio(0), 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: 173ms
memory: 3548kb

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:

1001
1
1011110110000100001
111010001100101000001010111011011100110001000110001
1101111110000101100101010111011001110010011000010000100
1111111111111111111111111000000000000000000000000001
10000000000000000000000000000000000000000000000000000
1011001110110001000110111110100100010001110001001011001
10...

result:

wrong answer 1st lines differ - expected: 'Case #1: 1001', found: '1001'

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: