답안 #303241

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
303241 2020-09-20T05:19:48 Z VROOM_VARUN 비밀 (JOI14_secret) C++14
100 / 100
512 ms 8388 KB
/*
ID: varunra2
LANG: C++
TASK: secret
*/

#include <bits/stdc++.h>
using namespace std;
#include "secret.h"

#ifdef DEBUG
#include "lib/debug.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define debug_arr(...) \
  cerr << "[" << #__VA_ARGS__ << "]:", debug_arr(__VA_ARGS__)
#pragma GCC diagnostic ignored "-Wsign-compare"
//#pragma GCC diagnostic ignored "-Wunused-parameter"
//#pragma GCC diagnostic ignored "-Wunused-variable"
#else
#define debug(...) 42
#endif

#define EPS 1e-9
#define IN(A, B, C) assert(B <= A && A <= C)
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define MP make_pair
#define PB push_back
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define x first
#define y second

const double PI = acos(-1.0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef map<int, int> MPII;
typedef multiset<int> MSETI;
typedef set<int> SETI;
typedef set<string> SETS;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<string> VS;

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
#pragma GCC diagnostic ignored "-Wsign-compare"
// util functions

VI vals;
int n;
int cnt = 0;

const int mxn = 1001;

VVI dp(mxn, VI(mxn));

// int Secret(int x, int y) {
//   cnt++;
//   return min(x + 2 * (y / 2), INF);
// }

void work(int l, int r) {
  // do dnc here

  if (l >= r) return;

  int mid = (l + r) / 2;

  dp[mid][mid] = vals[mid];
  dp[mid + 1][mid + 1] = vals[mid + 1];

  for (int i = mid + 2; i <= r; i++) {
    dp[mid + 1][i] = Secret(dp[mid + 1][i - 1], vals[i]);
  }

  for (int i = mid - 1; i >= l; i--) {
    dp[mid][i] = Secret(vals[i], dp[mid][i + 1]);
  }

  work(l, mid);
  work(mid + 1, r);
}

void Init(int N, int a[]) {
  n = N;
  vals.resize(n);
  for (int i = 0; i < n; i++) {
    vals[i] = a[i];
  }

  work(0, n - 1);
}

int Query(int l, int r) {
  int tl, tr;
  tl = 0;
  tr = n - 1;
  while (tl < tr) {
    int tm = (tl + tr) / 2;
    if (tm >= l and tm < r) return Secret(dp[tm][l], dp[tm + 1][r]);
    if (tm == r) return dp[tm][l];
    if (tm < l)
      tl = tm + 1;
    else
      tr = tm;
  }

  return dp[tl][tl];
}

// int main() {
// #ifndef ONLINE_JUDGE
//   freopen("secret.in", "r", stdin);
//   freopen("secret.out", "w", stdout);
// #endif
//   cin.sync_with_stdio(0);
//   cin.tie(0);

//   int n;
//   cin >> n;

//   int vals[n];

//   for (int i = 0; i < n; i++) {
//     cin >> vals[i];
//   }

//   Init(n, vals);

//   int q;
//   cin >> q;

//   while (q--) {
//     int l, r;
//     cin >> l >> r;
//     cout << Query(l, r) << '\n';
//   }

//   for (int i = 0; i < mxn; i++) {
//     debug(i, dp[i]);
//   }

//   debug(cnt);

//   return 0;
// }
# 결과 실행 시간 메모리 Grader output
1 Correct 149 ms 6392 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 148 ms 6392 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 152 ms 6392 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 512 ms 8360 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 509 ms 8312 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 503 ms 8312 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 507 ms 8312 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 509 ms 8388 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 505 ms 8312 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 506 ms 8340 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1