Submission #303239

# Submission time Handle Problem Language Result Execution time Memory
303239 2020-09-20T05:08:30 Z VROOM_VARUN Secret (JOI14_secret) C++14
0 / 100
512 ms 8420 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 - 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;
// }
# Verdict Execution time Memory Grader output
1 Correct 146 ms 6520 KB Output is correct - number of calls to Secret by Init = 3331, maximum number of calls to Secret by Query = 1
2 Correct 146 ms 6520 KB Output is correct - number of calls to Secret by Init = 3339, maximum number of calls to Secret by Query = 1
3 Incorrect 139 ms 6392 KB Wrong Answer: Query(67, 224) - expected : 202440844, actual : 536870912.
4 Incorrect 497 ms 8312 KB Wrong Answer: Query(384, 458) - expected : 896057572, actual : 536870912.
5 Incorrect 495 ms 8312 KB Wrong Answer: Query(263, 292) - expected : 653448456, actual : 536870912.
6 Incorrect 498 ms 8420 KB Wrong Answer: Query(738, 741) - expected : 983692994, actual : 942318537.
7 Correct 509 ms 8332 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
8 Correct 512 ms 8312 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
9 Correct 512 ms 8312 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
10 Correct 510 ms 8312 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1