답안 #303237

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
303237 2020-09-20T05:05:46 Z VROOM_VARUN 비밀 (JOI14_secret) C++14
0 / 100
500 ms 8824 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 = 10;

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 - 1);
  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][tr];
}

// 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 Runtime error 134 ms 4732 KB Execution killed with signal 11
2 Runtime error 134 ms 4728 KB Execution killed with signal 11
3 Runtime error 132 ms 4856 KB Execution killed with signal 11
4 Runtime error 495 ms 8776 KB Execution killed with signal 11
5 Runtime error 499 ms 8696 KB Execution killed with signal 11
6 Runtime error 498 ms 8692 KB Execution killed with signal 11
7 Runtime error 500 ms 8644 KB Execution killed with signal 11
8 Runtime error 495 ms 8824 KB Execution killed with signal 11
9 Runtime error 498 ms 8568 KB Execution killed with signal 11
10 Runtime error 494 ms 8568 KB Execution killed with signal 11