답안 #235775

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
235775 2020-05-29T19:52:16 Z Blagojce 비밀 (JOI14_secret) C++11
0 / 100
503 ms 8568 KB
#include <bits/stdc++.h> 
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
#include <time.h>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const ll inf = 1e18;
const ll mod = 1000000007;
const ld eps = 1e-13;
const ld pi  = 3.14159265359;
 
mt19937 _rand(time(NULL));
clock_t timer = clock();
const int mxn = 5e5 + 5;

#include "secret.h"


int n;
int a[1001];



/*
Segment tree solution
* MAX calls to Secret by Init = 999
* MAX calls to Secret by Query = 16


int seg[10000];
void build(int k, int l, int r){
	if(l == r){
		seg[k] = a[l];
		return;
	}
	int mid = (l + r) / 2;
	build(k * 2, l, mid);
	build(k * 2 + 1, mid + 1, r);
	seg[k] = Secret(seg[k * 2], seg[k * 2 + 1]);
}
vector<int> v;
void query(int k, int l, int r, int x, int y){
	
	if(y < l || r < x) return;
	if(x <= l && r <= y){
		v.pb(seg[k]);
		return;
	}
	int mid = (l + r) / 2;
	query(k * 2, l, mid, x, y);
	query(k * 2 + 1, mid + 1, r, x, y);
}
int Query(int L, int R){
	
	v.clear();
	query(1, 0, n - 1, L, R);
	int ans = v[0];
	fr(i, 1, (int)v.size()){
		ans = Secret(ans, v[i]);
	}
	
	return ans;
}
 */
 
/**
Sparse table solution
* MAX calls to Secret by Init = 7987
* MAX calls to Secret by Query = 8
int sparse[10001][10];
void Init(int N, int A[]) {
	n = N;
	fr(i, 0, N){
		a[i] = A[i];
		sparse[i][0] = a[i];
	}
	fr(i, 1, 10){
		for(int j = 0; j + (1 << i) - 1 < n; j ++){
			sparse[j][i] = Secret(sparse[j][i - 1], sparse[j + (1<<(i-1))][i - 1]);
		}
	}
}
int Query(int L, int R){
	int len = (R - L + 1);
	int ans = -1;
	for(int i = 9; i >= 0; i --){
		if(len & (1 << i)){
			if(ans == -1){
				ans = sparse[L][i];
			}
			else{
				ans = Secret(ans, sparse[L][i]);
			}
			L += (1 << i);
		}
	}
	return ans;
}
**/

//Meet in the middle technique:


int v[1000][1000];
void f(int l, int r){
	if(l == r){
		v[l][r] = a[l];
		return;
	}
	int mid = (l + r) / 2;
	v[mid][mid] = a[mid];
	v[mid][mid + 1] = Secret(a[mid], a[mid + 1]);
	
	for(int i = mid - 1; i >= 0; i --){
		v[i][mid] = Secret(a[i], v[i + 1][mid]);  
	}
	for(int i = mid + 2; i < n; i ++){
		v[mid + 1][i] = Secret(v[mid + 1][i - 1], a[i]);
	}
	f(l, mid);
	f(mid + 1, r);
}

void Init(int N, int A[]) {
	n = N;
	fr(i, 0, N){
		a[i] = A[i];
	}
	memset(v, -1, sizeof(v));
	f(0, n - 1);
	
	
	
}
int Query(int L, int R){
	if(v[L][R] != -1) return v[L][R];
	if(L + 1 == R){
		return Secret(a[L], a[R]);
	}
	fr(i, L, R){
		if(v[L][i] != -1 && v[i + 1][R] != -1) return Secret(v[L][i], v[i + 1][R]);
	}
	
}




/*

int main(){
	int N;
	cin >> N;
	int A[N];
	fr(i, 0, N){
		cin >> A[i];
	}
	Init(N, A);
	int Q;
	cin >> Q;
	while(Q --){
		int L, R;
		cin >> L >> R;
		Query(L, R);
	}

}
*/

Compilation message

secret.cpp: In function 'int Query(int, int)':
secret.cpp:151:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 134 ms 6392 KB Wrong Answer [1]
2 Incorrect 140 ms 6432 KB Wrong Answer [1]
3 Incorrect 140 ms 6344 KB Wrong Answer [1]
4 Incorrect 492 ms 8196 KB Wrong Answer [1]
5 Incorrect 489 ms 8312 KB Wrong Answer [1]
6 Incorrect 498 ms 8312 KB Wrong Answer [1]
7 Incorrect 494 ms 8312 KB Wrong Answer [1]
8 Incorrect 497 ms 8568 KB Wrong Answer [1]
9 Incorrect 499 ms 8284 KB Wrong Answer [1]
10 Incorrect 503 ms 8216 KB Wrong Answer [1]