QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#811852#9783. Duloc NetworkI_Love_Sonechka#WA 1ms3776kbC++203.2kb2024-12-13 03:33:102024-12-13 03:33:10

Judging History

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

  • [2024-12-13 03:33:10]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3776kb
  • [2024-12-13 03:33:10]
  • 提交

answer

#include <complex.h>
#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pi pair<int, int>
#define pb push_back

using namespace std;
using ll = long long;

template<typename T_container, typename T = typename enable_if
    <!is_same<T_container, string>::value, typename
    T_container::value_type>::type>

ostream& operator<<(ostream &os, const T_container &v) {
    os << '{';
    string sep;
    for(const T &x : v) {
        os << sep << x;
        sep = ", ";
    }
    return os << '}';
}


void dbg_out(){cerr<<endl;}
template <typename Head, typename... Tail>void dbg_out(Head H
    , Tail... T){cerr << ' ' << H; dbg_out(T...); }

#define dbg(...) dbg_out(__VA_ARGS__)

// #define TEST_CASES
#define vt vector

const int amax = 12;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void get() {
    int n = 200;
    double res = 0;
    for(int i = 1; i < n; ++i) {
        double P = 1;
        for(int j = 1; j <= i; ++j) {
            P /= i;
            res += P * j;
            P *= (i-1);
        }
    }
    cout << 2 * res << '\n';
}

const int MAX_QUERIES = 3500;

void solve() {
    int n; cin >> n;
    map<string, int> queries;
    auto Ask = [&](string s) -> int {
        if(queries.count(s)) {
            return queries[s];
        }
        if(queries.size() == MAX_QUERIES) {
            cout << "! " << rng() % 2 << endl;
            exit(0);
        }
        assert(queries.size() < MAX_QUERIES);
        cout << "? " << s << endl;
        fflush(stdout);
        int ret; cin >> ret;
        return queries[s] = ret;
    };
    string S;
    for(int i = 0; i < n; ++i) {
        S.push_back('0');
    }
    string T = S;
    S[rng()%n] = '1';
    for(int i = 1; i < n; ++i) {
        vt<int> other;
        for(int j = 0; j < n; ++j) if(S[j] == '0') {
            other.push_back(j);
        }
        int value = Ask(S);
        if(value == n - i) {
            break;
        }
        if(value == 0) {
            cout << "! 0" << endl;
            fflush(stdout);
            return ;
        }
        // stable_sort(other.begin(), other.end(), [&](int x, int y) -> bool {
        //     T[x] = '1';
        //     auto ask_x = Ask(T);
        //     T[x] = '0';
        //     T[y] = '1';
        //     auto ask_y = Ask(T);
        //     T[y] = '0';
        //     return ask_x < ask_y;
        // });
        shuffle(other.begin(), other.end(), rng);
        if(i >= n/2) {
            cout << "! 1\n";
            return ;
        }
        for(auto u: other) {
            T[u] = '1';
            int u_value = Ask(T);
            T[u] = '0';
            S[u] = '1';
            int u_and_s = Ask(S);
            S[u] = '0';
            int s_value = Ask(S);
            int inter = s_value + u_value - u_and_s;
            if(inter != 0) {
                S[u] = '1';
                break;
            }
        }
    }
    cout << "! 1" << endl;
    fflush(stdout);
}

int main() {
    // cin.tie(0)->sync_with_stdio(0);
int tt = 1;
#ifdef TEST_CASES
    cin >> tt;
#endif
    while(tt--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3556kb

input:

4
1
2
2

output:

? 1000
? 0001
? 1001
! 1

result:

ok Correct answer with 3 queries.

Test #2:

score: 0
Accepted
time: 1ms
memory: 3776kb

input:

2
0

output:

? 10
! 0

result:

ok Correct answer with 1 queries.

Test #3:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

4
1
2
2

output:

? 1000
? 0010
? 1010
! 1

result:

ok Correct answer with 3 queries.

Test #4:

score: 0
Accepted
time: 1ms
memory: 3652kb

input:

2
0

output:

? 10
! 0

result:

ok Correct answer with 1 queries.

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 3568kb

input:

50
2
2
4
2
4
3
5
1
3
3
5
1
3
1
3
2
4
1
3
4
6
2
4
3
5
1
3
3
5
3
5
2
4
1
3
2
4
2
4
3
5
1
3
3
5
1
3
1
3
1
3
6
5
7
7
7
3
5
1
6
2
7
3
6
7
3
9
7
8
7
7
8
8
9
6
9
4
9
11
4
13
16
14
13
15
13
16
14
15
17
1
15
14
15
17
1
15
16
3
14
13
13
1
14
14
12
14
14
14
16
4
13
4
14
16
15
13
13
1
12

output:

? 00000000000000000000000000000001000000000000000000
? 00000000000000000000000000000000000000000000010000
? 00000000000000000000000000000001000000000000010000
? 00000000000000000000000000000000000100000000000000
? 00000000000000000000000000000001000100000000000000
? 000000000000000000000000000000000...

result:

wrong answer Wrong answer.