Submission #217213

# Submission time Handle Problem Language Result Execution time Memory
217213 2020-03-29T08:49:57 Z tselmegkh Secret (JOI14_secret) C++14
100 / 100
555 ms 8364 KB
#include<bits/stdc++.h>
#include "secret.h"
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 1e5 + 5, inf = 1e9;
#define pb push_back
#define mp make_pair
#define ll long long
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define sz(x) (int)x.size()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int ans[1005][1005], b[1005];

void solve(int l, int r){
	if(l == r){
		return;
	}
	int mid = (l + r) / 2;
	for(int i = mid - 1; i >= l; i--){
		if(ans[i][mid] == -1)ans[i][mid] = Secret(b[i], ans[i + 1][mid]);
	}
	for(int i = mid + 2; i <= r; i++){
		if(ans[mid + 1][i] == -1)ans[mid + 1][i] = Secret(ans[mid + 1][i - 1], b[i]);
	}
	solve(l, mid);
	solve(mid + 1, r);
}
void Init(int n, int a[]){
	memset(ans, -1, sizeof ans);
	for(int i = 0; i < n; i++)b[i] = a[i];
	for(int i = 0; i < n; i++){
		ans[i][i] = a[i];
	}
	solve(0, n - 1);
}
int Query(int ql, int qr){
	if(ans[ql][qr] != -1)return ans[ql][qr];
	for(int i = ql; i < qr; i++){
		if(ans[ql][i] != -1 && ans[i + 1][qr] != -1){
			return Secret(ans[ql][i], ans[i + 1][qr]);
		}
	}
}

Compilation message

secret.cpp: In function 'int Query(int, int)':
secret.cpp:55:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 157 ms 6392 KB Output is correct - number of calls to Secret by Init = 3084, maximum number of calls to Secret by Query = 1
2 Correct 156 ms 6392 KB Output is correct - number of calls to Secret by Init = 3092, maximum number of calls to Secret by Query = 1
3 Correct 162 ms 6396 KB Output is correct - number of calls to Secret by Init = 3101, maximum number of calls to Secret by Query = 1
4 Correct 552 ms 8312 KB Output is correct - number of calls to Secret by Init = 6989, maximum number of calls to Secret by Query = 1
5 Correct 541 ms 8320 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
6 Correct 542 ms 8364 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
7 Correct 539 ms 8312 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
8 Correct 549 ms 8312 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
9 Correct 545 ms 8304 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
10 Correct 555 ms 8312 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1