답안 #40055

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
40055 2018-01-26T05:12:00 Z funcsr 비밀 (JOI14_secret) C++14
6 / 100
715 ms 7608 KB
#include "secret.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define index(x, y) (int)(lower_bound(all(x), y) - x.begin())
#define pb push_back
#define NIL 1145141919
#define MAX_N (1<<10)
typedef pair<int, int> P;
int seg[MAX_N*2-1];
map<P, int> mp;
int ask(int x, int y) {
  if (mp.find(P(x, y)) != mp.end()) return mp[P(x, y)];
  return mp[P(x, y)] = Secret(x, y);
}
int op(int x, int y) {
  if (x == NIL) return y;
  if (y == NIL) return x;
  return ask(x, y);
}
int query(int a, int b, int k=0, int l=0, int r=MAX_N) {
  if (b <= l || r <= a) return NIL;
  if (a <= l && r <= b) return seg[k];
  return op(query(a, b, k*2+1, l, (l+r)/2), query(a, b, k*2+2, (l+r)/2, r));
}

int N;
void Init(int NN, int A[]) {
  N = NN;
  fill(seg, seg+MAX_N*2-1, NIL);
  rep(i, N) seg[i+MAX_N-1] = A[i];
  for (int i=MAX_N-2; i>=0; i--) {
    seg[i] = op(seg[i*2+1], seg[i*2+2]);
  }
  rep(i, N) {
    rep(j, 20) {
      int p = (1<<j)-1;
      if (p >= N) break;
      if (p >= i) query(i, p+1);
    }
  }
  rep(i, N) {
    rep(j, 20) {
      int p = (1<<j);
      if (p <= i) query(p, i+1);
    }
  }
}

int Query(int L, int R) {
  int b = L-1;
  rep(j, 20) {
    int p = (1<<j)-1;
    if (p >= R) break;
    if (p >= L) b = p;
  }
  return op(query(L, b+1), query(b+1, R+1));
}
# 결과 실행 시간 메모리 Grader output
1 Partially correct 224 ms 7080 KB Output is partially correct - number of calls to Secret by Init = 6113, maximum number of calls to Secret by Query = 6
2 Correct 235 ms 7080 KB Output is correct - number of calls to Secret by Init = 7145, maximum number of calls to Secret by Query = 1
3 Correct 215 ms 7080 KB Output is correct - number of calls to Secret by Init = 7155, maximum number of calls to Secret by Query = 1
4 Incorrect 698 ms 7608 KB Output isn't correct - number of calls to Secret by Init = 13662, maximum number of calls to Secret by Query = 7
5 Incorrect 715 ms 7608 KB Output isn't correct - number of calls to Secret by Init = 13678, maximum number of calls to Secret by Query = 8
6 Incorrect 659 ms 7344 KB Output isn't correct - number of calls to Secret by Init = 13678, maximum number of calls to Secret by Query = 3
7 Incorrect 686 ms 7476 KB Output isn't correct - number of calls to Secret by Init = 13678, maximum number of calls to Secret by Query = 1
8 Incorrect 676 ms 7476 KB Output isn't correct - number of calls to Secret by Init = 13678, maximum number of calls to Secret by Query = 1
9 Incorrect 678 ms 7476 KB Output isn't correct - number of calls to Secret by Init = 13678, maximum number of calls to Secret by Query = 1
10 Incorrect 657 ms 7476 KB Output isn't correct - number of calls to Secret by Init = 13678, maximum number of calls to Secret by Query = 1