답안 #370161

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
370161 2021-02-23T13:25:34 Z arnold518 비교 (balkan11_cmp) C++14
46 / 100
9078 ms 105068 KB
#include "cmp.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int A, B;

void remember(int _A)
{
	A=_A;
	vector<int> V;
	for(int i=11; i>=0; i--)
	{
		if(A&(1<<i)) V.push_back(1);
		else V.push_back(0);
	}

	int val=0;
	for(int i=0; i<V.size(); i++)
	{
		val=val*2+V[i];
		int t=(1<<(i+1))-1;
		bit_set(t+val);
	}
}

int compare(int _B)
{
	B=_B;

	vector<int> V, VV;
	for(int i=11; i>=0; i--)
	{
		if(B&(1<<i)) V.push_back(1);
		else V.push_back(0);
	}

	int val=0;
	for(int i=0; i<V.size(); i++)
	{
		val=val*2+V[i];
		VV.push_back(val);
	}

	int lo=-1, hi=12;

	while(lo+1<hi)
	{
		int mid=lo+hi>>1;

		int t=(1<<(mid+1))-1;
		if(bit_get(t+VV[mid])) lo=mid;
		else hi=mid;
	}
	if(hi==12) return 0;

	if(V[hi]) return 1;
	else return -1;
}

Compilation message

cmp.cpp: In function 'void remember(int)':
cmp.cpp:22:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |  for(int i=0; i<V.size(); i++)
      |               ~^~~~~~~~~
cmp.cpp: In function 'int compare(int)':
cmp.cpp:42:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |  for(int i=0; i<V.size(); i++)
      |               ~^~~~~~~~~
cmp.cpp:52:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   52 |   int mid=lo+hi>>1;
      |           ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 9078 ms 105068 KB Output is partially correct - maxAccess = 16, score = 46