답안 #244221

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
244221 2020-07-03T01:24:56 Z MohamedAhmed04 Password (RMI18_password) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std ;

const int MAX = 1e5 + 10 ;

int arr[MAX] , freq[27] , before[27][27] , letters[MAX] ;
int n , c ;

string ans = "" ;

int query(string s);

bool Check_Before(int a , int b)
{
	string s = ans ;
	s.push_back((char)(a+'a')) ;
	for(int i = 0 ; i < freq[b] ; ++i)
		s.push_back((char)(b+'a')) ;
	return (query(s) == s.size()) ;
}

bool cmp(int &a , int &b)
{
	return before[a][b] ;
}

int main()
{
	//ios_base::sync_with_stdio(0) ;
	//cin.tie(0) ;
	cin>>n>>c ;
	for(int i = 0 ; i < c ; ++i)
		freq[i] = Query(string(n , (char)('a'+i))) ;
	for(int i = 0 ; i < c ; ++i)
	{
		for(int j = i+1 ; j < c ; ++j)
		{
			before[i][j] = Check_Before(i , j) ;
			if(!before[i][j])
				before[j][i] = 1 ;
		}
	}
	for(int i = 0 ; i < c ; ++i)
		letters[i] = i ;
	sort(letters , letters + c , cmp) ;
	for(int i = 0 ; i < n ; ++i)
	{
		int x = letters[0] ;
		freq[x]-- ;
		ans.push_back((char)(x+'a')) ;
		int l = 1 , r = c-1 ;
		int idx = 0 ;
		if(freq[x] == 0)
			idx = c-1 ;
		else
		{
			while(l <= r)
			{
				int mid = (l + r) >> 1 ;
				if(!Check_Before(letters[0] , letters[mid]))
					idx = mid , l = mid+1 ;
				else
					r = mid-1 ;
			}
		}
		for(int i = 0 ; i < idx ; ++i)
			letters[i] = letters[i+1] ;
		letters[idx] = x ;
	}
	query(ans) ;
	return 0 ;
}		

Compilation message

password.cpp: In function 'bool Check_Before(int, int)':
password.cpp:20:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  return (query(s) == s.size()) ;
          ~~~~~~~~~^~~~~~~~~~~
password.cpp: In function 'int main()':
password.cpp:34:13: error: 'Query' was not declared in this scope
   freq[i] = Query(string(n , (char)('a'+i))) ;
             ^~~~~
password.cpp:34:13: note: suggested alternative: 'query'
   freq[i] = Query(string(n , (char)('a'+i))) ;
             ^~~~~
             query