Submission #21125

# Submission time Handle Problem Language Result Execution time Memory
21125 2017-04-04T18:25:24 Z sbansalcs Secret (JOI14_secret) C++14
100 / 100
623 ms 13860 KB
#include "secret.h"
#include <iostream>

#include <vector>
const int N = 1002;
using namespace std;

// vector<int> vt[N];
int val[N][N];
int hav[N][N];
int X[N];

void comp(int a, int b)  {
    if(a>=b)    return ;
    if(b-a==1)  {
    	hav[a][b]=1;
    	val[a][b]=Secret(X[a],X[b]);
    }
    else    {
        int f=(a+b)/2;
        int f2=f+1;
        for(int i=f-1;i>=a;i--)	{
        	hav[i][f]=1;
        	if(i==f-1)	val[i][f]=Secret(X[i],X[f]);
        	else	val[i][f]=Secret(X[i],val[i+1][f]);
        }
        f++;
        for(int i=f+1;i<=b;i++)	{
        	hav[f][i]=1;
        	if(i==f+1)	val[f][i]=Secret(X[f],X[i]);
        	else	val[f][i]=Secret(val[f][i-1],X[i]);
        }
        f--;

        if(hav[f][f2]==0)	{
        	hav[f][f2]=1;
        	val[f][f2]=Secret(X[f],X[f2]);
        }
        comp(a,f-1);
        comp(f2+1,b);
    }
}


void Init(int N, int A[]) {
  // Secret(0, 1000000000);
	for(int i=1;i<=N;i++)	X[i]=A[i-1];
	for(int i=1;i<=N;i++)	{
		hav[i][i]=1;
		val[i][i]=X[i];
	}
	comp(1,N);
}

int Query(int L, int R) {
	L++,R++;
	if(L==R)	return X[L];
	else if(hav[L][R])	return val[L][R];
	for(int i=L;i<=R-1;i++)	{
		if(hav[L][i] && hav[i+1][R])	return Secret(val[L][i],val[i+1][R]);
	}
	// cout<<"shit!\n";
  return -1;
}

Compilation message


# Verdict Execution time Memory Grader output
1 Correct 169 ms 13860 KB Output is correct - number of calls to Secret by Init = 3339, maximum number of calls to Secret by Query = 1
2 Correct 169 ms 13860 KB Output is correct - number of calls to Secret by Init = 3347, maximum number of calls to Secret by Query = 1
3 Correct 176 ms 13860 KB Output is correct - number of calls to Secret by Init = 3355, maximum number of calls to Secret by Query = 1
4 Correct 593 ms 13860 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
5 Correct 619 ms 13860 KB Output is correct - number of calls to Secret by Init = 7485, maximum number of calls to Secret by Query = 1
6 Correct 596 ms 13860 KB Output is correct - number of calls to Secret by Init = 7485, maximum number of calls to Secret by Query = 1
7 Correct 606 ms 13860 KB Output is correct - number of calls to Secret by Init = 7485, maximum number of calls to Secret by Query = 1
8 Correct 613 ms 13860 KB Output is correct - number of calls to Secret by Init = 7485, maximum number of calls to Secret by Query = 1
9 Correct 619 ms 13860 KB Output is correct - number of calls to Secret by Init = 7485, maximum number of calls to Secret by Query = 1
10 Correct 623 ms 13860 KB Output is correct - number of calls to Secret by Init = 7485, maximum number of calls to Secret by Query = 1