답안 #748946

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
748946 2023-05-27T07:47:15 Z 반딧불(#9966) Mađioničar (COI22_madionicar) C++17
100 / 100
1784 ms 1600 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n;
int arr[200002];
int ans;

bool query(int l, int r){
    assert(l%2 == r%2);
    if(l%2==0) return true;

    printf("? %d %d\n", (l+1)/2, (r+1)/2);
    fflush(stdout);
    int x;
    scanf("%d", &x);
    return x;
}

int main(){
    scanf("%d", &n);
    n = 2*n-1;
    int maxV = 0, maxMid = 0;
    for(int i=1; i<=n; i++){
        if(maxV < i){ /// �ٱ����̶� �� �� ���� ���
            for(int l=1; i+l<=n+1 && i-l>=0; l++){
                if(!query(i-l, i+l)) break;
                arr[i] = l;
            }
        }
        else{ /// ������ ���
            int m = maxMid, mlen = arr[m];
            int l = maxMid-mlen, r = maxMid+mlen;
            int q = i, p = m+m-q, plen = arr[p];
            if(p-plen > l) arr[q] = arr[p];
            else if(p-plen < l) arr[q] = r-q;
            else{
                arr[q] = p-l;
                for(int l=arr[q]+1; i+l<=n+1 && i-l>=0; l++){
                    if(!query(i-l, i+l)) break;
                    arr[q] = l;
                }
            }
        }
        if(maxV <= i+arr[i]) maxV = i+arr[i], maxMid = i;
        ans = max(ans, arr[i]);
    }

    printf("! %d", ans);
}

Compilation message

Main.cpp: In function 'bool query(int, int)':
Main.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     scanf("%d", &x);
      |     ~~~~~^~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 308 KB Output is correct
2 Correct 122 ms 424 KB Output is correct
3 Correct 106 ms 336 KB Output is correct
4 Correct 103 ms 304 KB Output is correct
5 Correct 122 ms 340 KB Output is correct
6 Correct 107 ms 456 KB Output is correct
7 Correct 151 ms 308 KB Output is correct
8 Correct 102 ms 316 KB Output is correct
9 Correct 137 ms 316 KB Output is correct
10 Correct 84 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 308 KB Output is correct
2 Correct 122 ms 424 KB Output is correct
3 Correct 106 ms 336 KB Output is correct
4 Correct 103 ms 304 KB Output is correct
5 Correct 122 ms 340 KB Output is correct
6 Correct 107 ms 456 KB Output is correct
7 Correct 151 ms 308 KB Output is correct
8 Correct 102 ms 316 KB Output is correct
9 Correct 137 ms 316 KB Output is correct
10 Correct 84 ms 324 KB Output is correct
11 Correct 830 ms 808 KB Output is correct
12 Correct 1016 ms 832 KB Output is correct
13 Correct 1036 ms 1136 KB Output is correct
14 Correct 1032 ms 856 KB Output is correct
15 Correct 1082 ms 764 KB Output is correct
16 Correct 864 ms 936 KB Output is correct
17 Correct 1002 ms 900 KB Output is correct
18 Correct 710 ms 904 KB Output is correct
19 Correct 1038 ms 928 KB Output is correct
20 Correct 782 ms 832 KB Output is correct
21 Correct 960 ms 836 KB Output is correct
22 Correct 1161 ms 936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1332 ms 1100 KB Output is correct
2 Correct 900 ms 1100 KB Output is correct
3 Correct 1364 ms 1400 KB Output is correct
4 Correct 1615 ms 1272 KB Output is correct
5 Correct 1684 ms 1600 KB Output is correct
6 Correct 1154 ms 1316 KB Output is correct
7 Correct 1606 ms 1332 KB Output is correct
8 Correct 1361 ms 1288 KB Output is correct
9 Correct 1240 ms 1176 KB Output is correct
10 Correct 1381 ms 1096 KB Output is correct
11 Correct 1574 ms 1188 KB Output is correct
12 Correct 1589 ms 1136 KB Output is correct
13 Correct 1263 ms 1152 KB Output is correct
14 Correct 1166 ms 1188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 308 KB Output is correct
2 Correct 122 ms 424 KB Output is correct
3 Correct 106 ms 336 KB Output is correct
4 Correct 103 ms 304 KB Output is correct
5 Correct 122 ms 340 KB Output is correct
6 Correct 107 ms 456 KB Output is correct
7 Correct 151 ms 308 KB Output is correct
8 Correct 102 ms 316 KB Output is correct
9 Correct 137 ms 316 KB Output is correct
10 Correct 84 ms 324 KB Output is correct
11 Correct 830 ms 808 KB Output is correct
12 Correct 1016 ms 832 KB Output is correct
13 Correct 1036 ms 1136 KB Output is correct
14 Correct 1032 ms 856 KB Output is correct
15 Correct 1082 ms 764 KB Output is correct
16 Correct 864 ms 936 KB Output is correct
17 Correct 1002 ms 900 KB Output is correct
18 Correct 710 ms 904 KB Output is correct
19 Correct 1038 ms 928 KB Output is correct
20 Correct 782 ms 832 KB Output is correct
21 Correct 960 ms 836 KB Output is correct
22 Correct 1161 ms 936 KB Output is correct
23 Correct 1332 ms 1100 KB Output is correct
24 Correct 900 ms 1100 KB Output is correct
25 Correct 1364 ms 1400 KB Output is correct
26 Correct 1615 ms 1272 KB Output is correct
27 Correct 1684 ms 1600 KB Output is correct
28 Correct 1154 ms 1316 KB Output is correct
29 Correct 1606 ms 1332 KB Output is correct
30 Correct 1361 ms 1288 KB Output is correct
31 Correct 1240 ms 1176 KB Output is correct
32 Correct 1381 ms 1096 KB Output is correct
33 Correct 1574 ms 1188 KB Output is correct
34 Correct 1589 ms 1136 KB Output is correct
35 Correct 1263 ms 1152 KB Output is correct
36 Correct 1166 ms 1188 KB Output is correct
37 Correct 855 ms 1124 KB Output is correct
38 Correct 1616 ms 1264 KB Output is correct
39 Correct 1615 ms 1188 KB Output is correct
40 Correct 1358 ms 1148 KB Output is correct
41 Correct 1639 ms 1244 KB Output is correct
42 Correct 1357 ms 1040 KB Output is correct
43 Correct 1622 ms 1164 KB Output is correct
44 Correct 1453 ms 1048 KB Output is correct
45 Correct 1770 ms 1252 KB Output is correct
46 Correct 1231 ms 1128 KB Output is correct
47 Correct 1165 ms 1288 KB Output is correct
48 Correct 1384 ms 1120 KB Output is correct
49 Correct 1448 ms 1292 KB Output is correct
50 Correct 1006 ms 1140 KB Output is correct
51 Correct 1784 ms 1192 KB Output is correct
52 Correct 1286 ms 1060 KB Output is correct