QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#124146#5874. Mystery Squaretraining4usaco0 0ms3412kbC++173.3kb2023-07-14 10:12:262023-07-14 10:12:28

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-14 10:12:28]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3412kb
  • [2023-07-14 10:12:26]
  • 提交

answer

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;

using i128 = __int128;

int n, mid;
string str;
i128 ans, mask0, mask1, tot;

void dfs1(int idx, i128 val, i128 s) {
    if(ans != -1) return;
    
    if(idx == mid) {
        if(!(((s * s) & mask0) || ((tot ^ (s * s)) & mask1))) {
            ans = s * s;
        }
        if(!((((s | (i128)1 << (idx - 1)) * (s | (i128)1 << (idx - 1))) & mask0) || ((tot ^ ((s | (i128)1 << (idx - 1)) * (s | (i128)1 << (idx - 1)))) & mask1))) {
            ans = (s | (i128)1 << (idx - 1)) * (s | (i128)1 << (idx - 1));
        }
        return;
    }
    
    int flag = ((s * s) >> idx) & 1;
    int next = flag;
    if(str[idx] == '?' || str[idx] == ('0' + (next & 1))) {
        dfs1(idx + 1, val | (i128)(next & 1) << idx, s);
    }
    next = flag + 1;
    if(idx == 2) ++next;
    if(str[idx] == '?' || str[idx] == ('0' + (next & 1))) {
        dfs1(idx + 1, val | (i128)(next & 1) << idx, s | i128(1) << (idx - 1));
    }
}

void dfs2(int idx, i128 val) {
    if(ans != -1) return;
    if(idx == mid - 1) {
        i128 x = sqrt((long long) val);
        while(x * x < val) ++x;
        while(((x * x) >> mid) == (val >> mid)) {
            if(!(((x * x) & mask0) || ((tot ^ (x * x)) & mask1))) {
                ans = x * x;
                break;
            }
            ++x;
        }
        return;
    }
    
    if(str[idx] == '?' || str[idx] == '0') dfs2(idx - 1, val);
    if(str[idx] == '?' || str[idx] == '1') dfs2(idx - 1, val | (i128)1 << idx);
}

int main() {
    cin.tie(0)->sync_with_stdio(false); cout.tie(0);
    int t, tot; cin >> t; tot = t;
    while(t--) {
        cin >> str; reverse(str.begin(), str.end());
        ans = -1;
        int i = 0;
        while(str.size()) {
            if(str[0] == '?' || str[0] == '1') {
                str[0] = '1';
                
                mid = (str.size() + 1) / 2;
                int lcnt = 0, rcnt = 0;
                for(int i = 0; i < mid; ++i) lcnt += str[i] == '?';
                for(int i = mid; i < str.size(); ++i) rcnt += str[i] == '?';
                
                mask0 = mask1 = tot = 0;
                for(int i = 0; i < str.size(); ++i) {
                    tot |= ((i128)1 << i);
                    if(str[i] == '?') continue;
                    if(str[i] == '0') mask0 |= ((i128)1 << i);
                    if(str[i] == '1') mask1 |= ((i128)1 << i);
                }
                
                if(lcnt < rcnt) {
                    // cout << "a" << endl;
                    dfs1(2, 1, 1);
                }
                else {
                    // cout << "b" << endl;
                    dfs2(str.size() - 1, 0);
                }
                
                if(ans != (i128)-1) {
                    cout << "Case #" << tot - t << ": ";
                    for(int i = str.size() - 1; i >= 0; --i) cout << (long long)((ans >> i) & 1);
                    for(int j = 1; j <= i; ++j) cout << '0';
                    cout << "\n"; break;
                }
                // cout << (long long)ans << endl;
            }
            str.erase(str.begin()); str.erase(str.begin());
            i += 2;
        }
    }
    return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3412kb

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 #-22: 0
Case #-21: 0000000000000000000
Case #-20: 000000000000000000000000000000000000000000000000000
Case #-19: 0000000000000000000000000000000000000000000000000000000
Case #-17: 00000000000000000000000000000000000000000000000000000
Case #-16: 00000000000000000000000000000000000000000000000000...

result:

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

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: