Submission #749052

# Submission time Handle Problem Language Result Execution time Memory
749052 2023-05-27T09:33:41 Z mariowong Secret (JOI14_secret) C++14
100 / 100
766 ms 17244 KB
#include "secret.h"
#include <bits/stdc++.h>
using namespace std;
map <pair<int,int>,pair<int,bool>  > m;
/*int Secret(int X,int Y){
	return min(X+2*(Y/2),1000000000);
}*/
int a[1005];
void ask(int l,int r,bool c){
	int mid=(l+r)/2;
	if (l != r){
		ask(l,mid,true);
		ask(mid+1,r,false);
	} 
	if (c){
		int val=a[r];
		for (int i=r-1;i>=l;i--){
			if (!m[{i,r}].second){
				val=Secret(a[i],val);
				m[{i,r}]={val,true};
			} 
			else
			val=m[{i,r}].first;
		}
	}
	else
	{
		int val=a[l];
		for (int i=l+1;i<=r;i++){
			if (!m[{l,i}].second){
				val=Secret(val,a[i]);
				m[{l,i}]={val,true};
			} 
			else
			val=m[{l,i}].first;
		}
	}
	
}
void Init(int N, int A[]) {
  	m.clear();
  	int mid=(N-1)/2;	
  	for (int i=0;i<N;i++) a[i]=A[i];
  	for (int i=0;i<N;i++) m[{i,i}]={a[i],true};
	ask(0,mid,true);
	ask(mid+1,N-1,false);
}

int Query(int L, int R) {
	if (m[{L,R}].second) return m[{L,R}].first;
	for (int i=L;i<R;i++){
		if (m[{L,i}].second && m[{i+1,R}].second) return Secret(m[{L,i}].first,m[{i+1,R}].first);
	}
  return 0;
}
/*
int a[105];
int main(){
	int n;
	cin >> n;
	for (int i=0;i<n;i++) cin >> a[i];
	Init(n,a);
	int q;
	cin >> q;
	for (int i=1;i<=q;i++){
		int u,v;
		cin >> u >> v;
		cout << Query(u,v) << "\n";
	}
}*/
# Verdict Execution time Memory Grader output
1 Correct 220 ms 6980 KB Output is correct - number of calls to Secret by Init = 3084, maximum number of calls to Secret by Query = 1
2 Correct 202 ms 6912 KB Output is correct - number of calls to Secret by Init = 3092, maximum number of calls to Secret by Query = 1
3 Correct 228 ms 7044 KB Output is correct - number of calls to Secret by Init = 3101, maximum number of calls to Secret by Query = 1
4 Correct 611 ms 17244 KB Output is correct - number of calls to Secret by Init = 6989, maximum number of calls to Secret by Query = 1
5 Correct 606 ms 17220 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
6 Correct 443 ms 5356 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
7 Correct 766 ms 9328 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
8 Correct 716 ms 11212 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
9 Correct 730 ms 11212 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
10 Correct 753 ms 11360 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1