Submission #1356512

#TimeUsernameProblemLanguageResultExecution timeMemory
1356512nguyenkhangninh99Worm Worries (BOI18_worm)C++20
32 / 100
0 ms396 KiB
#include <stdio.h>
#include <math.h>

int main(){
    int n, m, k, q;
    scanf("%d %d %d %d", &n, &m, &k, &q);
    int l = 1, r = n;
    double p = (sqrt(5) - 1) / 2;
    int x1 = r - (int)((r - l) * p), x2 = l + (int)((r - l) * p);
    int v1, v2;
    printf("? %d 1 1\n", x1); fflush(stdout); scanf("%d", &v1);
    printf("? %d 1 1\n", x2); fflush(stdout); scanf("%d", &v2);
    int s = 33;
    while(s--){
        int g = (v1 < v2);
        l = g ? x1 : l;
        r = g ? r : x2;
        int tx1 = x1, tx2 = x2, tv1 = v1, tv2 = v2;
        g ? (x1 = tx2, v1 = tv2, x2 = l + (int)((r - l) * p)) : (x2 = tx1, v2 = tv1, x1 = r - (int)((r - l) * p));
        g ? (x1 == x2 ? x2++ : 0, printf("? %d 1 1\n", x2), fflush(stdout), scanf("%d", &v2)) : (x1 == x2 ? x1-- : 0, printf("? %d 1 1\n", x1), fflush(stdout), scanf("%d", &v1));
    }
    printf("! %d 1 1\n", (v1 > v2 ? x1 : x2));
    fflush(stdout);
    return 0;
}

Compilation message (stderr)

worm.cpp: In function 'int main()':
worm.cpp:6:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 |     scanf("%d %d %d %d", &n, &m, &k, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
worm.cpp:11:52: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     printf("? %d 1 1\n", x1); fflush(stdout); scanf("%d", &v1);
      |                                               ~~~~~^~~~~~~~~~~
worm.cpp:12:52: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     printf("? %d 1 1\n", x2); fflush(stdout); scanf("%d", &v2);
      |                                               ~~~~~^~~~~~~~~~~
worm.cpp:20:82: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         g ? (x1 == x2 ? x2++ : 0, printf("? %d 1 1\n", x2), fflush(stdout), scanf("%d", &v2)) : (x1 == x2 ? x1-- : 0, printf("? %d 1 1\n", x1), fflush(stdout), scanf("%d", &v1));
      |                                                                             ~~~~~^~~~~~~~~~~
worm.cpp:20:166: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         g ? (x1 == x2 ? x2++ : 0, printf("? %d 1 1\n", x2), fflush(stdout), scanf("%d", &v2)) : (x1 == x2 ? x1-- : 0, printf("? %d 1 1\n", x1), fflush(stdout), scanf("%d", &v1));
      |                                                                                                                                                                 ~~~~~^~~~~~~~~~~
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...