Submission #574704

# Submission time Handle Problem Language Result Execution time Memory
574704 2022-06-09T09:37:22 Z SlavicG Secret (JOI14_secret) C++17
100 / 100
436 ms 12332 KB
#include "secret.h"
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long
 
#define       forn(i,n)              for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
 
#define            pb                push_back
#define          sz(a)               (int)a.size()

const int N = 1005;
int val[N][N], mm[N][N];
/*
int Secret(int l, int r) {
    return 69;
} 
*/

void build(int l, int r) {
    if(l >= r) return;
    int mid = l + r >> 1;

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

    for(int i = l; i <= mid; ++i) {
        for(int j = mid + 1; j <= r; ++j) {
            mm[i][j] = mid;
        }
    }

    build(l, mid);
    build(mid + 1, r);
}
void Init(int n, int a[]) {
    forn(i, N) forn(j, N) val[i][j] = -1;
    forn(i, n) val[i][i] = a[i];
    build(0, n - 1);
}

int Query(int l, int r) {
    if(val[l][r] != -1) return val[l][r];
    int mid = mm[l][r];
    return Secret(val[l][mid], val[mid + 1][r]);
}

/*
void solve() {  
    
}   
     
int32_t main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
}
*/

Compilation message

secret.cpp: In function 'void build(int, int)':
secret.cpp:24:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   24 |     int mid = l + r >> 1;
      |               ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 122 ms 8272 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 123 ms 8264 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 127 ms 8272 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 430 ms 12076 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 434 ms 12120 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 430 ms 12100 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 435 ms 12116 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 436 ms 12124 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 435 ms 12332 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 433 ms 12104 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1