제출 #1371040

#제출 시각아이디문제언어결과실행 시간메모리
1371040eradaxA Difficult(y) Choice (BOI21_books)C++20
컴파일 에러
0 ms0 KiB
#include "books.h"
#include <bits/stdc++.h>

/*
Either the answer is K consecutive numbers or
the first K-1 numbers and then the first number >= A

if all values are < A, the sum when moving one value can never change by any
value >= A. Therefore the solution can be found by moving from left to right and
taking the smallest value to the largest.
*/

#define setcontains(c, x) (c.find(x) != c.end())

unordered_map<int, ll> q;
ll mskim(int a) {
  a++;

  if (setcontains(q, a)) {
    return q[a];
  }

  return q[a] = skim(a);
}

void solve(int N, int K, ll A, int S) {
  q.clear();

  int f = 0;
  ll sum = 0;

  {
    int lo = 0;
    int hi = N - 1;
    while (lo < hi) {
      int mi = lo + (hi - lo) / 2;

      ll v = mskim(mi);

      if (v < A) {
        lo = mi + 1;
      } else {
        hi = mi;
      }
    }

    if (mskim(lo) >= A) {
      f = lo;
    } else {
      f = N;
    }
  }

  rep(i, K - 1) {
    sum += mskim(i);
  }

  if (f < N) {
    sum += mskim(f);

    if (A <= sum && sum <= 2 * A) {
      vi ans(K);
      rep(i, K - 1) ans[i] = i + 1;
      ans[K - 1] = f + 1;

      answer(ans);
      return;
    }

    sum -= mskim(f);
  }

  sum += mskim(K - 1);

  if (A <= sum && sum <= 2 * A) {
    vi ans(K);
    rep(i, K) ans[i] = i + 1;

    answer(ans);
    return;
  }

  int i = 0;
  while (i < K && f - 1 - i >= K) {
    sum -= mskim(i);
    sum += mskim(f - i - 1);

    if (A <= sum && sum <= 2 * A) {
      vi ans(K);
      rep(j, K - i - 1) {
        ans[j] = i + 1 + j + 1;
      }
      rep(j, i + 1) {
        ans[K - i - 1 + j] = f - i + j;
      }

      answer(ans);
      return;
    }

    i++;
  }

  impossible();
  return;
}

컴파일 시 표준 에러 (stderr) 메시지

books.cpp:15:20: error: 'll' was not declared in this scope
   15 | unordered_map<int, ll> q;
      |                    ^~
books.cpp:15:20: error: 'll' was not declared in this scope
books.cpp:15:20: error: 'll' was not declared in this scope
books.cpp:15:20: error: 'll' was not declared in this scope
books.cpp:15:20: error: 'll' was not declared in this scope
books.cpp:15:20: error: 'll' was not declared in this scope
books.cpp:15:20: error: 'll' was not declared in this scope
books.cpp:15:20: error: 'll' was not declared in this scope
books.cpp:15:20: error: 'll' was not declared in this scope
books.cpp:15:1: error: 'unordered_map' does not name a type
   15 | unordered_map<int, ll> q;
      | ^~~~~~~~~~~~~
books.cpp:16:1: error: 'll' does not name a type
   16 | ll mskim(int a) {
      | ^~
books.cpp:26:26: error: 'll' has not been declared
   26 | void solve(int N, int K, ll A, int S) {
      |                          ^~
books.cpp: In function 'void solve(int, int, int, int)':
books.cpp:27:3: error: 'q' was not declared in this scope
   27 |   q.clear();
      |   ^
books.cpp:30:3: error: 'll' was not declared in this scope
   30 |   ll sum = 0;
      |   ^~
books.cpp:38:9: error: expected ';' before 'v'
   38 |       ll v = mskim(mi);
      |         ^~
      |         ;
books.cpp:40:11: error: 'v' was not declared in this scope
   40 |       if (v < A) {
      |           ^
books.cpp:47:9: error: 'mskim' was not declared in this scope; did you mean 'skim'?
   47 |     if (mskim(lo) >= A) {
      |         ^~~~~
      |         skim
books.cpp:54:7: error: 'i' was not declared in this scope
   54 |   rep(i, K - 1) {
      |       ^
books.cpp:54:3: error: 'rep' was not declared in this scope
   54 |   rep(i, K - 1) {
      |   ^~~
books.cpp:59:5: error: 'sum' was not declared in this scope
   59 |     sum += mskim(f);
      |     ^~~
books.cpp:59:12: error: 'mskim' was not declared in this scope; did you mean 'skim'?
   59 |     sum += mskim(f);
      |            ^~~~~
      |            skim
books.cpp:62:7: error: 'vi' was not declared in this scope
   62 |       vi ans(K);
      |       ^~
books.cpp:64:7: error: 'ans' was not declared in this scope; did you mean 'abs'?
   64 |       ans[K - 1] = f + 1;
      |       ^~~
      |       abs
books.cpp:73:3: error: 'sum' was not declared in this scope
   73 |   sum += mskim(K - 1);
      |   ^~~
books.cpp:73:10: error: 'mskim' was not declared in this scope; did you mean 'skim'?
   73 |   sum += mskim(K - 1);
      |          ^~~~~
      |          skim
books.cpp:76:5: error: 'vi' was not declared in this scope
   76 |     vi ans(K);
      |     ^~
books.cpp:79:12: error: 'ans' was not declared in this scope; did you mean 'abs'?
   79 |     answer(ans);
      |            ^~~
      |            abs
books.cpp:89:7: error: 'vi' was not declared in this scope
   89 |       vi ans(K);
      |       ^~
books.cpp:90:11: error: 'j' was not declared in this scope
   90 |       rep(j, K - i - 1) {
      |           ^
books.cpp:97:14: error: 'ans' was not declared in this scope; did you mean 'abs'?
   97 |       answer(ans);
      |              ^~~
      |              abs