이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
string s,ans;
int st,ed;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n; cin>>n;
cin>>s;
if (s.size()%2==0) {
cout<<"NOT POSSIBLE";
return 0;
}
//consider insert letter in the middle
bool ok=true;
for (int i=0; i<s.size()/2; ++i) {
if (s[i]!=s[i+s.size()/2+1]) ok=false;
}
if (ok) {
for (int i=0; i<s.size()/2; ++i) ans+=s[i];
}
//consider insert letter on the left string
for (int i=0; i<=s.size()/2; ++i) {
if (s[i]!=s[i+s.size()/2+1] || i==s.size()/2) {
ed=i;
break;
}
}
for (int i=s.size()/2; i>=0; --i) {
if (s[i]!=s[i+s.size()/2] || i==0) {
st=i;
break;
}
}
if (st<ed) {
cout<<"NOT UNIQUE";
return 0;
} else if (st==ed) {
if (ans.size()==0) {
int k=0,idx=0;
while (k<s.size()/2) {
if (st!=idx) ans+=s[idx], ++k;
++idx;
}
} else {
bool check=true;
int k=0,idx=0;
while (k<s.size()/2) {
if (st!=idx){
if (ans[k]!=s[idx]) {
cout<<"NOT UNIQUE";
return 0;
} else ++k;
}
++idx;
}
}
}
//consider insert letter on the right string
for (int i=s.size()/2; i<s.size(); ++i) {
if (s[i]!=s[i-s.size()/2] || i==s.size()-1) {
ed=i;
break;
}
}
for (int i=s.size()-1; i>=s.size()/2; --i) {
if (s[i]!=s[i-s.size()/2-1] || i==s.size()/2) {
st=i;
break;
}
}
if (st<ed) {
cout<<"NOT UNIQUE";
return 0;
} else if (st==ed) {
if (ans.size()==0) {
int k=0,idx=0;
while (k<s.size()/2) {
if (st!=idx) ans+=s[idx], ++k;
++idx;
}
} else {
bool check=true;
int k=0,idx=0;
while (k<s.size()/2) {
if (st!=idx){
if (ans[k]!=s[idx]) {
cout<<"NOT UNIQUE";
return 0;
} else ++k;
}
++idx;
}
}
}
if (ans.size()==0) cout<<"NOT POSSIBLE";
else cout<<ans;
}
컴파일 시 표준 에러 (stderr) 메시지
friends.cpp: In function 'int main()':
friends.cpp:19:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for (int i=0; i<s.size()/2; ++i) {
| ~^~~~~~~~~~~
friends.cpp:23:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for (int i=0; i<s.size()/2; ++i) ans+=s[i];
| ~^~~~~~~~~~~
friends.cpp:27:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for (int i=0; i<=s.size()/2; ++i) {
| ~^~~~~~~~~~~~
friends.cpp:28:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | if (s[i]!=s[i+s.size()/2+1] || i==s.size()/2) {
| ~^~~~~~~~~~~~
friends.cpp:45:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | while (k<s.size()/2) {
| ~^~~~~~~~~~~
friends.cpp:52:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | while (k<s.size()/2) {
| ~^~~~~~~~~~~
friends.cpp:50:18: warning: unused variable 'check' [-Wunused-variable]
50 | bool check=true;
| ^~~~~
friends.cpp:65:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for (int i=s.size()/2; i<s.size(); ++i) {
| ~^~~~~~~~~
friends.cpp:66:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | if (s[i]!=s[i-s.size()/2] || i==s.size()-1) {
| ~^~~~~~~~~~~~
friends.cpp:71:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for (int i=s.size()-1; i>=s.size()/2; --i) {
| ~^~~~~~~~~~~~
friends.cpp:72:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | if (s[i]!=s[i-s.size()/2-1] || i==s.size()/2) {
| ~^~~~~~~~~~~~
friends.cpp:83:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | while (k<s.size()/2) {
| ~^~~~~~~~~~~
friends.cpp:90:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | while (k<s.size()/2) {
| ~^~~~~~~~~~~
friends.cpp:88:18: warning: unused variable 'check' [-Wunused-variable]
88 | bool check=true;
| ^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |