Submission #244222

# Submission time Handle Problem Language Result Execution time Memory
244222 2020-07-03T01:25:49 Z MohamedAhmed04 Password (RMI18_password) C++14
Compilation error
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()) ;
          ~~~~~~~~~^~~~~~~~~~~
/tmp/cc3Ko7DQ.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccTQsG6O.o:password.cpp:(.text.startup+0xc0): first defined here
/tmp/cc3Ko7DQ.o: In function `main':
grader.cpp:(.text.startup+0x5f): undefined reference to `guess[abi:cxx11](int, int)'
collect2: error: ld returned 1 exit status