QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#627377#7804. Intersegment ActivationIllusionaryDominance#RE 1ms3960kbC++201.9kb2024-10-10 15:44:132024-10-10 15:44:13

Judging History

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

  • [2024-10-10 15:44:13]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3960kb
  • [2024-10-10 15:44:13]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 10 + 5;

int n;

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 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

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
0
0
0
1
0
1
1
2
3

output:

1 1
1 2
1 1
1 1
1 1
2 2
2 3
2 2

result:

ok OK, 8 queries

Test #2:

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

input:

1
0
1

output:

1 1

result:

ok OK, 1 queries

Test #3:

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

input:

2
1
2

output:

1 1

result:

ok OK, 1 queries

Test #4:

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

input:

2
0
0
1
0
1
2

output:

1 1
1 2
1 1
1 1
2 2

result:

ok OK, 5 queries

Test #5:

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

input:

2
0
1
0
1
2

output:

1 1
1 1
1 1
2 2

result:

ok OK, 4 queries

Test #6:

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

input:

2
0
0
1
2

output:

1 1
1 2
1 1

result:

ok OK, 3 queries

Test #7:

score: -100
Runtime Error

input:

3
0
0
0
0

output:

1 1
1 2
1 1
1 0

result: