제출 #484283

#제출 시각아이디문제언어결과실행 시간메모리
484283MohamedAhmed04세 명의 친구들 (BOI14_friends)C++14
100 / 100
10 ms6200 KiB
#include <bits/stdc++.h>

using namespace std ;

const int MAX = 2e6 + 10 ;

int arr[MAX] ;
int n ;

string s ;

bool check(string s2 , int l , int r)
{
	int idx = 0 ;
	int rem = 1 ;
	for(int i = l ; i <= r && idx < s2.size() ; ++i)
	{
		if(s[i] == s2[idx])
			++idx ;
		else
			rem-- ;
	}
	return (idx == s2.size() && rem >= 0) ;
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n ;
	cin>>s ;
	if(n%2 == 0)
		return cout<<"NOT POSSIBLE\n" , 0 ;
	bool flag1 = check(s.substr(0 , n/2) , n/2 , n-1) ;
	bool flag2 = check(s.substr(n-n/2 , n/2) , 0 , n/2) ;
	if(!flag1 && !flag2)
		cout<<"NOT POSSIBLE\n" ;
	else if(flag1 && flag2 && s.substr(0 , n/2) != s.substr(n-n/2 , n/2))
		cout<<"NOT UNIQUE\n" ;
	else if(flag1)
		cout<<s.substr(0 , n/2)<<"\n" ;
	else
		cout<<s.substr(n-n/2 , n/2) ;
	return 0 ;
}		

컴파일 시 표준 에러 (stderr) 메시지

friends.cpp: In function 'bool check(std::string, int, int)':
friends.cpp:16:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  for(int i = l ; i <= r && idx < s2.size() ; ++i)
      |                            ~~~~^~~~~~~~~~~
friends.cpp:23:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  return (idx == s2.size() && rem >= 0) ;
      |          ~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...