답안 #40053

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
40053 2018-01-26T05:06:20 Z funcsr 비밀 (JOI14_secret) C++14
30 / 100
656 ms 7212 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);
    }
  }
}

int Query(int L, int R) {
  int b = L;
  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 206 ms 7080 KB Output is partially correct - number of calls to Secret by Init = 1279, maximum number of calls to Secret by Query = 11
2 Partially correct 213 ms 7080 KB Output is partially correct - number of calls to Secret by Init = 2304, maximum number of calls to Secret by Query = 8
3 Partially correct 207 ms 7080 KB Output is partially correct - number of calls to Secret by Init = 2305, maximum number of calls to Secret by Query = 8
4 Partially correct 653 ms 7212 KB Output is partially correct - number of calls to Secret by Init = 2791, maximum number of calls to Secret by Query = 12
5 Partially correct 640 ms 7212 KB Output is partially correct - number of calls to Secret by Init = 2792, maximum number of calls to Secret by Query = 11
6 Partially correct 613 ms 7080 KB Output is partially correct - number of calls to Secret by Init = 2792, maximum number of calls to Secret by Query = 4
7 Partially correct 653 ms 6816 KB Output is partially correct - number of calls to Secret by Init = 2792, maximum number of calls to Secret by Query = 8
8 Partially correct 656 ms 6948 KB Output is partially correct - number of calls to Secret by Init = 2792, maximum number of calls to Secret by Query = 8
9 Partially correct 645 ms 6948 KB Output is partially correct - number of calls to Secret by Init = 2792, maximum number of calls to Secret by Query = 8
10 Partially correct 644 ms 6948 KB Output is partially correct - number of calls to Secret by Init = 2792, maximum number of calls to Secret by Query = 8