답안 #342331

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
342331 2021-01-01T22:31:50 Z ogibogi2004 비교 (balkan11_cmp) C++14
100 / 100
5214 ms 96128 KB
#include "cmp.h"
#include<bits/stdc++.h>
using namespace std;
void remember(int n) {
  //edit this
    string s="";
    for(int i=0;i<6;i++)
    {
		s+=char('0'+n%4);
		n/=4;
	}
	reverse(s.begin(),s.end());
	int t=0;
	for(int i=0;i<s.size();i++)
	{
		t=t*4+s[i]-'0'+1;
		bit_set(t);
	}
}

int compare(int b) {
  //edit this
	string s="";
    for(int i=0;i<6;i++)
    {
		s+=char('0'+b%4);
		b/=4;
	}
	reverse(s.begin(),s.end());
	int t=0;
	vector<int>v;
	for(int i=0;i<s.size();i++)
	{
		t=t*4+s[i]-'0'+1;
		v.push_back(t);
	}
	int high=s.size()-1,low=0,ans=-1;
	while(low<=high)
	{
		int mid=(low+high)/2;
		if(bit_get(v[mid]))
		{
			ans=mid;
			low=mid+1;
		}
		else high=mid-1;
	}
	if(ans==s.size()-1)return 0;
	int j=s[ans+1]-'0';
	int k;
	if(ans==-1)k=0;
	else k=v[ans];
	if(j<2)
	{
		for(int l=0;l<j;l++)
		{
			if(bit_get(k*4+l+1))return 1;
		}
		return -1;
	}
	else
	{
		for(int l=j+1;l<4;l++)
		{
			if(bit_get(k*4+l+1))return -1;
		}
		return 1;
	}
	return -1;
	return 0;
    return bit_get(13);
}

Compilation message

cmp.cpp: In function 'void remember(int)':
cmp.cpp:14:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for(int i=0;i<s.size();i++)
      |              ~^~~~~~~~~
cmp.cpp: In function 'int compare(int)':
cmp.cpp:32:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |  for(int i=0;i<s.size();i++)
      |              ~^~~~~~~~~
cmp.cpp:48:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |  if(ans==s.size()-1)return 0;
      |     ~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5214 ms 96128 KB Output is correct - maxAccess = 10, score = 100