# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
362263 | denkendoemeer | Secret (JOI14_secret) | C++14 | 539 ms | 8556 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "secret.h"
#include<bits/stdc++.h>
int ans[1005][1005];
void calc(int st,int dr)
{
int mij=(st+dr)/2,i;
if (st==dr || st==dr-1)
return ;
for(i=mij-1;i>=st;i--)
if (ans[i][mij]==-1)
ans[i][mij]=Secret(ans[i][i+1],ans[i+1][mij]);
for(i=mij+1;i<=dr;i++)
if (ans[mij][i]==-1)
ans[mij][i]=Secret(ans[mij][i-1],ans[i-1][i]);
calc(st,mij);
calc(mij,dr);
}
void Init(int n,int a[])
{
int i,j;
memset(ans,-1,sizeof(ans));
for(i=0;i<n;i++)
ans[i][i+1]=a[i];
calc(0,n);
}
int Query(int l,int r)
{
int i;
for(i=l+1;i<=r;i++)
if (ans[l][i]!=-1 && ans[i][r+1]!=-1)
return Secret(ans[l][i],ans[i][r+1]);
return ans[l][r+1];
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |