답안 #4817

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
4817 2014-01-04T12:35:43 Z tncks0121 XOR (IZhO12_xor) C++
100 / 100
252 ms 58284 KB
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <memory.h> 
#include <math.h> 
#include <assert.h> 
#include <stack> 
#include <queue> 
#include <map> 
#include <set> 
#include <algorithm> 
#include <string> 
#include <functional> 
#include <vector> 
#include <deque> 
#include <utility> 
#include <bitset> 
#include <limits.h>  
#include <time.h>

using namespace std; 
typedef long long ll; 
typedef unsigned long long llu; 
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;

const int N_ = 250005;
int N, X, D[N_];

struct node {
	int x;
	node *child[2];
	node(): x(0) { child[0] = NULL; child[1] = NULL; }
};

node *root;

int res_i, res_k;
const int MAXB = 30;

int main() {
	int i, j, k;

	scanf("%d%d", &N, &X);
	for(i = 1; i <= N; i++) {
		int v; scanf("%d", &v);
		D[i] = D[i-1] ^ v;
	}

	root = new node;
	root->x = 0;
	
	for(i = 0; i <= N; i++) {
		node *now = root;
		for(k = MAXB; k >= 0; k--) {
			int d = (D[i] & (1<<k)) >> k;
			if(now->child[d] == NULL) now->child[d] = new node;
			now->child[d]->x = i;
			now = now->child[d];
		}
	}

	for(i = 0; i < N; i++) {
		node *now = root;
		int r = 0;
		for(k = MAXB; k >= 0; k--) {
			int d = (D[i] & (1<<k)) >> k;
			int x = (X    & (1<<k)) >> k;
			if(x == 0 && now->child[!d] != NULL) r = max(r, now->child[!d]->x);
			now = now->child[d^x];
			if(now == NULL) break;
		}
		if(now != NULL) r = max(r, now->x);
		if(res_k < r-i) res_i = i+1, res_k = r-i;
	}

	printf("%d %d\n", res_i, res_k);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2184 KB Output is correct
2 Correct 0 ms 2184 KB Output is correct
3 Correct 0 ms 2184 KB Output is correct
4 Correct 0 ms 2316 KB Output is correct
5 Correct 12 ms 3504 KB Output is correct
6 Correct 16 ms 3636 KB Output is correct
7 Correct 16 ms 3636 KB Output is correct
8 Correct 12 ms 3768 KB Output is correct
9 Correct 84 ms 28584 KB Output is correct
10 Correct 80 ms 28716 KB Output is correct
11 Correct 84 ms 28452 KB Output is correct
12 Correct 88 ms 28584 KB Output is correct
13 Correct 84 ms 28584 KB Output is correct
14 Correct 92 ms 28716 KB Output is correct
15 Correct 84 ms 28584 KB Output is correct
16 Correct 88 ms 28584 KB Output is correct
17 Correct 224 ms 58152 KB Output is correct
18 Correct 240 ms 58152 KB Output is correct
19 Correct 252 ms 58284 KB Output is correct
20 Correct 232 ms 58152 KB Output is correct