답안 #645526

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
645526 2022-09-27T09:48:25 Z Alex_tz307 Floppy (RMI20_floppy) C++17
100 / 100
88 ms 15680 KB
#include <bits/stdc++.h>
#include "floppy.h"

using namespace std;

/*
#define NMAX 100000
#define MMAX 100000

int subtask_id, N, M;
vector<int> v, sorted_v;
vector<int> a, b;
vector<int> correct_answers;

// Print score to stdout and exit.
void score_and_exit(const double pts, const char *verdict) {
  fprintf(stderr, "%s", verdict);
  fprintf(stdout, "%f", pts);
  exit(0);
}

// Contestant sent too many bits.
void too_many_bits() {
  score_and_exit(0, "Too many stored bits!");
}

// Contestant did not send any bits.
void misformatted_stored_bits() {
  score_and_exit(0, "Misformatted stored bits or save_to_floppy not called!");
}

// Contestant did not call the answer function.
void answer_not_provided() {
  score_and_exit(0, "Answer not provided!");
}

// Contestant sent a wrong answer.
void wrong_answer() {
  score_and_exit(0, "Wrong answer to query!");
}

// Contestant sent a correct answer.
void correct_answer() {
  score_and_exit(1, "OK!");
}

void read_test() {
  assert(scanf("%d", &subtask_id) == 1);
  assert(scanf("%d%d", &N, &M) == 2);
  assert(1 <= N && N <= NMAX);
  assert(0 <= M && M <= MMAX);
  v.resize(N);
  for (int i = 0; i < N; ++i) {
    assert(scanf("%d", &v[i]) == 1);
  }

  // Check all values are distinct.
  sorted_v.resize(N);
  for (int i = 0; i < N; ++i) {
    sorted_v[i] = v[i];
  }
  sort(sorted_v.begin(), sorted_v.end());
  for (int i = 0; i + 1 < N; ++i) {
    assert(sorted_v[i] < sorted_v[i + 1]);
  }

  a.resize(M);
  b.resize(M);
  correct_answers.resize(M);
  for (int i = 0; i < M; ++i) {
      assert(scanf("%d%d%d", &a[i], &b[i], &correct_answers[i]) == 3);
      assert(0 <= a[i] && a[i] <= correct_answers[i] &&
            correct_answers[i] <= b[i] && b[i] < N);
  }
}
*/

vector<int> solve_queries(int subtask_id, int n, const string &bits, const vector<int> &a, const vector<int> &b) {
  vector<int> lg2(n + 1);
  for (int i = 2; i <= n; ++i) {
    lg2[i] = lg2[i / 2] + 1;
  }
  vector<vector<int>> nxt(n + 1, vector<int>(lg2[n] + 1, n));
  vector<int> stk;
  int ptr = 0;
  for (int i = 0; i < n; ++i) {
    while (bits[ptr] == '0') {
      nxt[stk.back()][0] = i;
      stk.pop_back();
      ptr += 1;
    }
    stk.emplace_back(i);
    ptr += 1;
  }
  for (int j = 1; j <= lg2[n]; ++j) {
    for (int i = 0; i < n; ++i) {
      nxt[i][j] = nxt[nxt[i][j - 1]][j - 1];
    }
  }
  int m = a.size();
  vector<int> res(m);
  for (int i = 0; i < m; ++i) {
    int l = a[i], r = b[i];
    for (int j = lg2[r - l + 1]; j >= 0; --j) {
      if (nxt[l][j] <= r) {
        l = nxt[l][j];
      }
    }
    res[i] = l;
  }
  return res;
}

/*
void save_to_floppy(const string &bits) {
  vector<int> contestant_answers = solve_queries(subtask_id, N, bits, a, b);
  for (int i = 0; i < M; ++i) {
    if (contestant_answers[i] != correct_answers[i]) {
      wrong_answer();
    }
  }
  correct_answer();
  exit(0);
}
*/

void read_array(int subtask_id, const vector<int> &v) {
  int n = v.size();
  vector<int> stk;
  string bits = "";
  for (int i = 0; i < n; ++i) {
    while (!stk.empty() && stk.back() < v[i]) {
      stk.pop_back();
      bits += '0';
    }
    stk.emplace_back(v[i]);
    bits += '1';
  }
  save_to_floppy(bits);
}

/*
int main(int argc, char **argv) {
  // Read input data.
  read_test();

  // Send subtask_id, v.
  read_array(subtask_id, v);

  answer_not_provided();
  return 0;
}
*/

Compilation message

stub.cpp: In function 'void run2()':
stub.cpp:101:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  101 |     if (query_answers.size() != M) {
      |         ~~~~~~~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 772 KB Output is correct
2 Correct 2 ms 808 KB Output is correct
3 Correct 2 ms 800 KB Output is correct
4 Correct 2 ms 800 KB Output is correct
5 Correct 2 ms 772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 3972 KB Output is correct
2 Correct 22 ms 3968 KB Output is correct
3 Correct 19 ms 3996 KB Output is correct
4 Correct 20 ms 3968 KB Output is correct
5 Correct 20 ms 4004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 88 ms 15332 KB Output is correct
2 Correct 87 ms 15468 KB Output is correct
3 Correct 81 ms 15680 KB Output is correct
4 Correct 83 ms 15508 KB Output is correct
5 Correct 86 ms 15404 KB Output is correct