답안 #302009

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
302009 2020-09-18T11:11:39 Z aloo123 비밀 (JOI14_secret) C++14
100 / 100
527 ms 8440 KB
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#include "secret.h"
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
// #define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;
 
 
const ll INF = 1e9;
const int M =(1e3+5); // TODO : change value as per problem
const ll MOD = 1e9+7;
int a[M];
int n;
int pref[M][M];
// int Secret(int x,int y){
//     return min(x+2*(y/2),1000000000);
// }
void divi(int l, int r) { // generate dat and mask
    // cout << l << " " << r << endl;
    // if(l < 1 || r > n || l > r) return;
    // if (l == r) {pref[l][l] = a[l];return;}

    int m = (l+r)>>1ll; 
    pref[m][m] = a[m];
    for(int i = m-1;i>=l;i--){
        pref[i][m] = Secret(a[i],pref[i+1][m]); 
    }
    pref[m+1][m+1] = a[m+1];
    for(int i = m+2;i<=r;i++){
        pref[m+1][i] = Secret(pref[m+1][i-1],a[i]);
    }
    
    if(l < m)
        divi(l,m);
    if((m+1) < r)
        divi(m+1,r);
}

 
 
void Init(int N,int A[]){
    n = N;
    for(int i = 0;i<n;i++){
        a[i+1] = A[i];
    }
    divi(1,n);
 
}
int Query(int L, int R){
    if(L == R){
        return a[L+1];
    }
        int a = 1, b = n;
        L++,R++;
    while (a != b) {
        int mid = (a + b) / 2;
        if (mid >= L && mid < R)
            return Secret(pref[L][mid], pref[mid + 1][R]);
        else if (mid == R) return pref[L][mid];
        else if (mid < L) a = mid + 1;
        else b = mid;
    }

 }

 
 
// void solve(){
    
// // }
// signed main(){
 
//     ios_base::sync_with_stdio(0);
//     // cin.tie(NULL);
//      // freopen(".in","r",stdin);freopen(".out","w",stdout);
//     int x;
//     cin >> x;
//     int v[x];
//     for(int i =0;i<x;i++){
//         cin >> v[i];
//     }
//     Init(x,v);
//     int q;
//     cin >> q;
//     while(q--){
//         int l,r;
//         cin>>l>>r;
//         cout<<Query(l,r)<<endl;
//     }
         
// }

Compilation message

secret.cpp: In function 'int Query(int, int)':
secret.cpp:104:2: warning: control reaches end of non-void function [-Wreturn-type]
  104 |  }
      |  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 144 ms 4344 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 145 ms 4472 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 147 ms 4472 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 505 ms 8332 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 510 ms 8316 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 504 ms 8312 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 519 ms 8312 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 511 ms 8240 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 527 ms 8440 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 526 ms 8284 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1