답안 #361898

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
361898 2021-01-31T22:58:44 Z Lemur95 비밀 (JOI14_secret) C++17
100 / 100
531 ms 8428 KB
#include <bits/stdc++.h>
#include "secret.h"
#pragma GCC optimize("Ofast")
#define x first
#define y second
#define ld long double
#define ll long long
#define ull unsigned long long
#define us unsigned short
#define lsb(x) ((x) & (-(x)))

using namespace std;

int n;

int v[1005], sum[1005][1005];

/*int Secret(int x, int y) {
  return x + y;
}*/

void divide(int st, int dr) {
  if(st == dr) {
    //sum[st][st] = v[st];
    return;
  }
  int mid = (st + dr) >> 1;
  for(int i = mid - 1; i >= st; i--)
    sum[i][mid] = Secret(v[i], sum[i + 1][mid]);
  for(int i = mid + 2; i <= dr; i++)
    sum[mid + 1][i] = Secret(sum[mid + 1][i - 1], v[i]);
  divide(st, mid);
  divide(mid + 1, dr);
}

void Init(int N, int a[]) {
  n = N;
  for(int i = 0; i < n; i++)
    v[i] = a[i], sum[i][i] = v[i];
  divide(0, n - 1);
}

int solve(int st, int dr, int l, int r) {
  int mid = (st + dr) >> 1;
  if(l == mid + 1 || mid == r)
    return sum[l][r];
  if(l <= mid && mid <= r)
    return Secret(sum[l][mid], sum[mid + 1][r]);
  if(r < mid)
    return solve(st, mid, l, r);
  return solve(mid + 1, dr, l, r);
}

int Query(int l, int r) {
  return solve(0, n - 1, l, r);
}

/*int main() {
  //ios_base :: sync_with_stdio(false);
  //cin.tie(0);
  //cout.tie(0);
  int n, Q, l, r, a[10005];
  cout << solve(0, 999, 653, 654) << "\n";
  cin >> n;
  for(int i = 0; i < n; i++)
    cin >> a[i];
  Init(n, a);
  cin >> Q;
  for(; Q; Q--) {
    cin >> l >> r;
    cout << Query(l, r) << "\n";
    int s = v[l];
    for(int i = l + 1; i <= r; i++)
      s = Secret(s, v[i]);
    cout << s << " right answer\n";
  }
  return 0;
}*/
# 결과 실행 시간 메모리 Grader output
1 Correct 152 ms 4588 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 142 ms 4380 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 142 ms 4460 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 514 ms 8300 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 8300 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 504 ms 8328 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 505 ms 8428 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 531 ms 8300 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 510 ms 8428 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 512 ms 8300 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1