답안 #480801

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
480801 2021-10-18T04:40:28 Z minhcool 비교 (balkan11_cmp) C++17
100 / 100
1603 ms 96012 KB
#include "cmp.h"
 
#define set_bit bit_set
#define get_bit bit_get
 
int min(int x, int y){
  return (x < y ? x : y);
}
 
void remember(int n) {
  //edit this
	set_bit(1 + ((n >> 10) & 3));
	set_bit(5 + ((n >> 8) & 15));
	set_bit(21 + ((n >> 6) & 63));
	set_bit(85 + ((n >> 4) & 255));
	set_bit(341 + ((n >> 2) & 1023));
	set_bit(1365 + (n & 4095));
    //set_bit(5461 + (n & 4095));
}
 
int compare(int b) {
  //edit this
  	int l = 0, r = 6;
  	while(l < r){
  		int mid = (l + r + 1) >> 1;
  		int pw = 1, sum = 0;
		for(int i = 1; i <= min(mid, 6); i++){
			sum += pw;
			pw *= 4;
		}  		
      	if(mid == 7) sum += pw;
		int temp = (b >> (12 - 2 * mid)) & (pw - 1);
		if(get_bit(sum + temp)) l = mid;
		else r = mid - 1;
	}
  	if(l == 6) return 0;
    l++;
	int tempor = (b >> (12 - 2 * l)) & 3;
	if(tempor >= 2){
		for(int i = tempor + 1; i <= 3; i++){
			b += (1LL << (12 - 2 * l));
			int sum = 0, pw = 1;
			for(int i = 1; i <= l; i++){
				sum += pw;
				pw *= 4;
			}
			int temp = (b >> (12 - 2 * l)) & (pw - 1);
			if(get_bit(sum + temp)) return -1;
		}
		return 1;
	}
	else{
		for(int i = tempor - 1; i >= 0; i--){
			b -= (1LL << (12 - 2 * l));
			int sum = 0, pw = 1;
			for(int i = 1; i <= l; i++){
				sum += pw;
				pw *= 4;
			}
			int temp = (b >> (12 - 2 * l)) & (pw - 1);
			if(get_bit(sum + temp)) return 1;
		}
		return -1;
	}
	//return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1603 ms 96012 KB Output is correct - maxAccess = 10, score = 100