QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#124148#5874. Mystery Squaretraining4usacoCompile Error//C++173.2kb2023-07-14 10:16:102023-07-14 10:16:11

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:16:11]
  • 评测
  • [2023-07-14 10:16:10]
  • 提交

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);
}

void solve(int 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;
    }
}

int main() {
    cin.tie(0)->sync_with_stdio(false);
    int t, tot; cin >> t; tot = t;
    while(t--) solve(tot - t);
    return 0;
}

Details

answer.code: In function ‘void solve(int)’:
answer.code:87:34: error: ambiguous overload for ‘operator<<’ (operand types are ‘std::basic_ostream<char>’ and ‘i128’ {aka ‘__int128’})
   87 |                 cout << "Case #" << tot - t << ": ";
      |                 ~~~~~~~~~~~~~~~~ ^~ ~~~~~~~
      |                      |                  |
      |                      |                  i128 {aka __int128}
      |                      std::basic_ostream<char>
In file included from /usr/include/c++/11/istream:39,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:3:
/usr/include/c++/11/ostream:166:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  166 |       operator<<(long __n)
      |       ^~~~~~~~
/usr/include/c++/11/ostream:170:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  170 |       operator<<(unsigned long __n)
      |       ^~~~~~~~
/usr/include/c++/11/ostream:174:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  174 |       operator<<(bool __n)
      |       ^~~~~~~~
In file included from /usr/include/c++/11/ostream:853,
                 from /usr/include/c++/11/istream:39,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:3:
/usr/include/c++/11/bits/ostream.tcc:91:5: note: candidate: ‘std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]’
   91 |     basic_ostream<_CharT, _Traits>::
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/istream:39,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:3:
/usr/include/c++/11/ostream:181:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  181 |       operator<<(unsigned short __n)
      |       ^~~~~~~~
In file included from /usr/include/c++/11/ostream:853,
                 from /usr/include/c++/11/istream:39,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:3:
/usr/include/c++/11/bits/ostream.tcc:105:5: note: candidate: ‘std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]’
  105 |     basic_ostream<_CharT, _Traits>::
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/istream:39,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:3:
/usr/include/c++/11/ostream:192:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  192 |       operator<<(unsigned int __n)
      |       ^~~~~~~~
/usr/include/c++/11/ostream:201:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  201 |       operator<<(long l...