제출 #394892

#제출 시각아이디문제언어결과실행 시간메모리
394892Nicholas_Patrick세 명의 친구들 (BOI14_friends)C++17
100 / 100
54 ms7180 KiB
#include <iostream>
#include <string>
using namespace std;

bool valid(string& s, string& a){
	int n=a.size();
	bool miss=false;
	for(int i=0, j=0; i<s.size(); i++){
		if(s[i]!=a[j]){
			if(miss)
				return false;
			miss=true;
		}else{
			j++;
			if(j==n)
				j=0;
		}
	}
	return true;
}
int main(){
	int n;
	string s;
	cin>>n>>s;
	if(~n&1){
		cout<<"NOT POSSIBLE"<<endl;
		return 0;
	}
	n>>=1;
	string a=s.substr(0, n), b=s.substr(n+1, n*2+1);
	if(valid(s, a)){
		if(valid(s, b)){
			if(a==b){
				cout<<a<<endl;
			}else{
				cout<<"NOT UNIQUE"<<endl;
			}
		}else{
			cout<<a<<endl;
		}
	}else{
		if(valid(s, b)){
			cout<<b<<endl;
		}else{
			cout<<"NOT POSSIBLE"<<endl;
		}
	}
}

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

friends.cpp: In function 'bool valid(std::string&, std::string&)':
friends.cpp:8:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |  for(int i=0, j=0; i<s.size(); i++){
      |                    ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...