Submission #213274

# Submission time Handle Problem Language Result Execution time Memory
213274 2020-03-25T12:01:39 Z HNO2 Secret (JOI14_secret) C++17
100 / 100
547 ms 8316 KB
#include "secret.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
//#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int ans[1007][1007];
int a[1007];

void solve(int l,int r)
{
    if (l==r) return;
    int m=(l+r)>>1;
    for (int i=m;i>=l;i--)
        if (ans[i][m]==-1)
            ans[i][m]=Secret(a[i],ans[i+1][m]);
    for (int i=m+1;i<=r;i++)
        if (ans[m+1][i]==-1) ans[m+1][i]=Secret(ans[m+1][i-1],a[i]);
    solve(l,m);
    solve(m+1,r);

}

void Init(int N, int A[])
{
    for (int i=0;i<N;i++)
        for (int j=0;j<N;j++) ans[i][j]=-1;
    for (int i=0;i<N;i++) ans[i][i]=A[i],a[i]=A[i];
    solve(0,N-1);
}

int Query(int L, int R) {
    if (ans[L][R]!=-1) return ans[L][R];
    else
    {
        for (int i=L;i<R;i++)
            if (ans[L][i]!=-1&&ans[i+1][R]!=-1) return Secret(ans[L][i],ans[i+1][R]);
    }
}

Compilation message

secret.cpp: In function 'int Query(int, int)':
secret.cpp:58:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 155 ms 4472 KB Output is correct - number of calls to Secret by Init = 3084, maximum number of calls to Secret by Query = 1
2 Correct 153 ms 4344 KB Output is correct - number of calls to Secret by Init = 3092, maximum number of calls to Secret by Query = 1
3 Correct 153 ms 4600 KB Output is correct - number of calls to Secret by Init = 3101, maximum number of calls to Secret by Query = 1
4 Correct 522 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 532 ms 8312 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
6 Correct 520 ms 8316 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
7 Correct 547 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 545 ms 8316 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
9 Correct 529 ms 8312 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
10 Correct 543 ms 8312 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1