Submission #1045373

# Submission time Handle Problem Language Result Execution time Memory
1045373 2024-08-05T21:18:59 Z Trent The Big Prize (IOI17_prize) C++14
Compilation error
0 ms 0 KB
#include "bits/stdc++.h"
using namespace std;

#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
struct pii{int a, b;};
typedef vector<int> vi;
vi getVal(int i, map<int, vi>& cache) {
    if(cache.count(i)) return cache[i];
    int[2] thing = ask(i);
  	vi ret;
  	ret[0] = thing[0], ret[1] = thing[1];
  	return cache[i] = ret;
}

void getBetter(int l, int r, int loid, int lOff, int rOff, map<int, vi>& cache) {
    assert(l <= r);
    int mid = (l + r) / 2;
    REP(ci, mid, r+1) {
        vi cv = getVal(ci, cache);
        if(cv[0] + cv[1] == loid) {
            if(cv[0] + lOff > 0) getBetter(l, ci - 1, loid, lOff, -cv[1], cache);
            if(cv[1] + rOff > 0) getBetter(ci+1, r, loid, -cv[0], rOff, cache);
            return; 
        }
    }
    for(int ci = mid - 1; ci >= l; --ci) {
        vi cv = getVal(ci, cache);
        if(cv[0] + cv[1] == loid) {
            if(cv[0] + lOff > 0) getBetter(l, ci - 1, loid, lOff, -cv[1], cache);
            if(cv[1] + rOff > 0) getBetter(ci+1, r, loid, -cv[0], rOff, cache);
            return; 
        }
    }
}

const int MV = 450;
int find_best(int n){
    map<int, vi> ca;
    forR(i, min(n, MV)) getVal(i, ca);
    int loVal = ca[0][0] + ca[0][1];
    forR(i, min(n, MV)) loVal = max(loVal, ca[i][0] + ca[i][1]);
    getBetter(0, n-1, loVal, 0, 0, ca);
    int bi = -1;
    for(auto [ci, cv] : ca) if(cv[0] + cv[1] == 0) {
        bi = ci;
    }
    assert(bi != -1);
    return bi;
}

Compilation message

prize.cpp: In function 'vi getVal(int, std::map<int, std::vector<int> >&)':
prize.cpp:10:9: error: expected identifier before numeric constant
   10 |     int[2] thing = ask(i);
      |         ^
prize.cpp:10:9: error: expected ']' before numeric constant
   10 |     int[2] thing = ask(i);
      |         ^
      |         ]
prize.cpp:10:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   10 |     int[2] thing = ask(i);
      |        ^
prize.cpp:10:8: error: structured binding declaration cannot have type 'int'
prize.cpp:10:8: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
prize.cpp:10:8: error: empty structured binding declaration
prize.cpp:10:12: error: expected initializer before 'thing'
   10 |     int[2] thing = ask(i);
      |            ^~~~~
prize.cpp:12:13: error: 'thing' was not declared in this scope
   12 |    ret[0] = thing[0], ret[1] = thing[1];
      |             ^~~~~
prize.cpp:10:8: warning: unused structured binding declaration [-Wunused-variable]
   10 |     int[2] thing = ask(i);
      |        ^
prize.cpp: In function 'int find_best(int)':
prize.cpp:45:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   45 |     for(auto [ci, cv] : ca) if(cv[0] + cv[1] == 0) {
      |              ^