Submission #599197

#TimeUsernameProblemLanguageResultExecution timeMemory
599197pakhomoveeThe Big Prize (IOI17_prize)C++17
Compilation error
0 ms0 KiB
#include "prize.h"
#include <vector>
#include <map>
#include <cassert>

int find_best(int n) {
    int pr = 0;
    std::map<int, int> d;
    int Q = 1;
    std::vector<int> q = ask(0);
      std::map<int, std::vector<int>> res;
      res[0] = q;
    int lt = q[0];
    int rt = q[1];
    int sm = lt + rt;
    if (sm == 0) {
        return 0;
    }
    while (pr != n) {
        int l = pr, r = n;
        while (l + 1 < r) {
            int m = (l + r) / 2;
            int have = 0;
            std::vector<int> q;
            if (!res.count(m)) {
                q = ask(m);
                res[m] = q;
            } else {
                q = res[m];
            }
              res[m] = q;
            ++Q;
            int lt = q[0];
            int rt = q[1];
            for (auto [x, y] : d) {
                if (lt + rt > x) {
                    have += y;
                }
            }
            if (lt - have) {
                r = m;
            } else {
                l = m;
            }
        }
        std::vector<int> arr
          if (!res.count(l)) {
              arr = ask(l);
              res[l] = arr;
          } else {
              arr = res[l];
          }
        ++Q;
        if (arr[0] == arr[1] && arr[0] == 0) {
            return l;
        }
        ++d[arr[0] + arr[1]];
        pr = l + 1;
        assert(arr[1] > 0);
    }
    return -1;
}

Compilation message (stderr)

prize.cpp: In function 'int find_best(int)':
prize.cpp:47:11: error: expected initializer before 'if'
   47 |           if (!res.count(l)) {
      |           ^~
prize.cpp:50:13: error: 'else' without a previous 'if'
   50 |           } else {
      |             ^~~~
prize.cpp:51:15: error: 'arr' was not declared in this scope
   51 |               arr = res[l];
      |               ^~~
prize.cpp:54:13: error: 'arr' was not declared in this scope
   54 |         if (arr[0] == arr[1] && arr[0] == 0) {
      |             ^~~
prize.cpp:57:13: error: 'arr' was not declared in this scope
   57 |         ++d[arr[0] + arr[1]];
      |             ^~~