QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#104894#6394. Turn on the Lightckiseki#WA 2ms3800kbC++141.3kb2023-05-12 12:33:002023-05-12 12:33:03

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-12 12:33:03]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3800kb
  • [2023-05-12 12:33:00]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
template <typename ...T>
void debug_(const char *s, T ...a) {
    cerr << "\e[1;32m(" << s << ") = (";
    int cnt = sizeof...(T);
    (..., (cerr << a << (--cnt ? ", " : ")\e[0m\n")));
}
template <typename I>
void orange_(const char *s, I L, I R) {
    cerr << "\e[1;32m[ " << s << " ] = [ ";
    for (int f = 0; L != R; ++L)
        cerr << (f++ ? ", " : "") << *L;
    cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif

int ask(int x) {
    printf("? %d\n", x);
    fflush(stdout);
    int y;
    scanf("%d", &y);
    return y;
}

int main() {
    int n;
    scanf("%d", &n);
    
    if (ask(1) == 0) {
        printf("! 1\n");
        return 0;
    }
    int L_R = 1;
    int L = 1, R = n + 1;
    while (R - L > 1) {
        int M = (L + R) >> 1;
        int v = ask(M);
        if (v == L_R - 1) {
            --L_R;
            R = M;
        } else if (v == L_R) {
            printf("! %d\n", M);
            break;
        } else {
            ++L_R;
            L = M;
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3800kb

input:

3
1
2
2

output:

? 1
? 2
? 3
! 3

result:

ok Correct position at 3

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3788kb

input:

10
1
0
1
2
3

output:

? 1
? 6
? 3
? 4
? 5

result:

wrong answer format  Unexpected end of file - token expected