QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#627373#7804. Intersegment ActivationIllusionaryDominance#Compile Error//C++201.9kb2024-10-10 15:43:222024-10-10 15:43:28

Judging History

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

  • [2024-10-10 15:43:28]
  • 评测
  • [2024-10-10 15:43:22]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 10 + 5;

int ask(int i, int j) {
    printf("%d %d\n", i, j);
    fflush(stdout);
    int res;
    scanf("%d", &res);
    if (res == n) {
        exit(0);
    }
    return res;
}

int gray_code[1 << 12], lowbit[1 << 12];

void gen_code(int n) {
    gray_code[0] = 0;
    for (int i = 1; i <= n; i ++) {
        for (int j = (1 << i - 1), k = (1 << i - 1) - 1; j < (1 << i); j ++, k --) {
            gray_code[j] = gray_code[k] | 1 << i - 1;
        }
    }
}

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 1, j = 1; i <= n; i <<= 1, j ++) lowbit[i] = j;
    for (int i = 0; i < n; i ++) {
        if (k != i) {
            for (int j = i + 1; j <= n; j ++) {
                int res = ask(j, j);
                if (res > k) {
                    res = ask(j, j);
                    assert(k == res);
                }else {
                    k = res;
                }
            }
        }
        assert(k == i);
        gen_code(n - i);
        for (int j = 1; j < (1 << n - i); j ++) {
            int diff = gray_code[j] ^ gray_code[j - 1];
            assert(diff == (diff & -diff));
            int res = ask(i + 1, i + lowbit[diff]);
            if (res > k) {
                int res2 = ask(i + 1, i + 1);
                if (res2 == res - 1) {
                    k = ask(i + 1, i + 1);
                    break;
                }
                res2 = ask(i + 1, i + 1);
                assert(res == res2);
                for (int l = i + 2; l <= n; l ++) {
                    res2 = ask(l, l);
                    if (res2 < res) {
                        res = res2;
                    }else {
                        res2 = ask(l, l);
                        assert(res == res2);
                    }
                }
            }
        }
    }
    assert(k == n);
    return 0;
}

Details

answer.code: In function ‘int ask(int, int)’:
answer.code:12:16: error: ‘n’ was not declared in this scope
   12 |     if (res == n) {
      |                ^
answer.code:11:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |     scanf("%d", &res);
      |     ~~~~~^~~~~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:31:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |     scanf("%d%d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~