이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define ii pair<int,int>
#define mp(a,b) make_pair(a,b)
#define null NULL;
int main(){
int n;
cin >> n;
string s;
cin >> s;
int all[26];
FOR(i,26)all[i] = 0;
FOR(i,n)all[s[i]-'A']++;
int pos = -1;
FOR(i,26){
if(all[i]%2 == 1){
if(pos == -1)pos = i;
else{
cout<<"NOT POSSIBLE"<<endl;
return 0;
}
}
}
int ctr = 0;
bool ok = false;
int pp = -1;
char cc = 'A' + pos;
bool cs1 = false;
//case 3. mid charac
bool cs3 = false;
{
string ss = "";
FOR(i,n){
if(i==n/2)continue;
ss+=s[i];
}
//cout <<ss<<endl;
string s1 = "";
FOR(i,n/2)s1+=ss[i];
s1+=s1;
// cout<<s1<<endl;
cs3 = (s1 == ss);
// cout<<"MC"<<cs3<<endl;
}
//cs4 somewhere else
int cnt1 = 0;
int cnt2 = 0;
FOR(i,n/2){
if(s[i] == cc)cnt1++;
if(s[i+n/2+1] == cc)cnt2++;
}
// cout << cnt1 << " " <<cnt2<<endl;
bool kk1 =false;bool kk2 = false;
if(cnt1 > cnt2){
string s1 = "";kk1= true;
string s2 = "";
FOR(i,n/2+1){
s1+=s[i];
if(i!=n/2)s2+=s[i+n/2+1];
}
// cout << s1<<" "<<s2 <<endl;
int ptr1=0;int ptr2 = 0;
bool ok1 = 0;
FOR(i,n/2){
if(s1[i+ok1]!=s2[i]){
if(ok1){
kk1 = false;
}
}
}
// cout << kk1 <<endl;
}else{
string s1 = "";
string s2 = "";kk2= true;
FOR(i,n/2+1){
if(i!=n/2)s1+=s[i];
s2+=s[i+n/2];
}
//bool kk =true;
// cout << s1<<" "<<s2 <<endl;
int ptr1=0;int ptr2 = 0;
bool ok1 = 0;
FOR(i,n/2){
if(s1[i+ok1]!=s2[i]){
if(ok1){
kk2 = false;
}
}
}
// cout << kk2 <<endl;
}
if((kk1 && kk2) || (kk1 && cs3) || (kk2 && cs3)){
cout << "NOT UNIQUE"<<endl;
}else if(cs3 || kk1 || kk2){
cout<<"POSSIBLE"<<endl;
}else{
cout << "NOT POSSIBLE"<<endl;
}
}
컴파일 시 표준 에러 (stderr) 메시지
friends.cpp: In function 'int main()':
friends.cpp:81:9: warning: unused variable 'ptr1' [-Wunused-variable]
int ptr1=0;int ptr2 = 0;
^~~~
friends.cpp:81:20: warning: unused variable 'ptr2' [-Wunused-variable]
int ptr1=0;int ptr2 = 0;
^~~~
friends.cpp:103:9: warning: unused variable 'ptr1' [-Wunused-variable]
int ptr1=0;int ptr2 = 0;
^~~~
friends.cpp:103:20: warning: unused variable 'ptr2' [-Wunused-variable]
int ptr1=0;int ptr2 = 0;
^~~~
friends.cpp:37:7: warning: unused variable 'ctr' [-Wunused-variable]
int ctr = 0;
^~~
friends.cpp:38:8: warning: unused variable 'ok' [-Wunused-variable]
bool ok = false;
^~
friends.cpp:39:7: warning: unused variable 'pp' [-Wunused-variable]
int pp = -1;
^~
friends.cpp:41:8: warning: unused variable 'cs1' [-Wunused-variable]
bool cs1 = false;
^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |