이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long i64;
#define speed_up ios::sync_with_stdio(false);cin.tie(nullptr);
#define ordered_set(datatype) tree<datatype,null_type,less<datatype>,rb_tree_tag,tree_order_statistics_node_update>
template<class T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define isON(N,K) (N&(1<<K))
#define endl '\n'
const int N = 2e3 + 7;
const int mod = 1e9 + 7;
const double PI = 3.14159265358979323846;
long double EPS = 1e-9;
const int dr[]={-1,0,1,0};
const int dc[]={0,1,0,-1};
template<class T>
istream &operator>>(istream &in, vector<T> &v) {
for (auto &it : v) in >> it;
return in;
}
template<class T>
ostream &operator<<(ostream &out, vector<T> &v) {
for (auto &it : v) out << it << ' ';
return out;
}
i64 powmod(i64 b,i64 p){
b%=mod;
i64 res=1;
while(p){
if(p&1)res=res*b%mod;
p>>=1;
b=b*b%mod;
}
return res;
}
i64 mul(i64 a,i64 b){
return ((a%mod)*(b%mod))%mod;
}
i64 inv(i64 b){
return powmod(b,mod-2);
}
string comp(string a,string b){
if(a.size()>b.size())swap(a,b);
int i=0,j=0,cnt=0;
while(i<a.size()&&j<b.size()){
while(j<b.size()&&a[i]==b[j]&&i<a.size()){
cnt++,j++,i++;
}
j++;
}
return (cnt==a.size()?a:"");;
}
void TC(){
int n;
cin >> n;
string s;
cin >> s;
if(n%2==0)return void(cout << "NOT POSSIBLE" << endl);
string a1,b1,a2,b2;
a1=s.substr(0,n/2),b1=s.substr(n/2);
a2=s.substr(0,n/2+1),b2=s.substr(n/2+1);
string ans1,ans2;
ans1=comp(a1,b1),ans2=comp(a2,b2);
if(!ans1.size()&&!ans2.size())cout << "NOT POSSIBLE" << endl;
else if(ans1.size()&&ans2.size()&&ans1!=ans2)cout << "NOT UNIQUE" << endl;
else cout << (ans1.size()? ans1:ans2) << endl;
}
signed main() {
speed_up
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int tt = 1;
// cin >> tt;
while(tt--) {
TC();
// cout << endl;
}
}
컴파일 시 표준 에러 (stderr) 메시지
friends.cpp: In function 'std::string comp(std::string, std::string)':
friends.cpp:58:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | while(i<a.size()&&j<b.size()){
| ~^~~~~~~~~
friends.cpp:58:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | while(i<a.size()&&j<b.size()){
| ~^~~~~~~~~
friends.cpp:59:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | while(j<b.size()&&a[i]==b[j]&&i<a.size()){
| ~^~~~~~~~~
friends.cpp:59:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | while(j<b.size()&&a[i]==b[j]&&i<a.size()){
| ~^~~~~~~~~
friends.cpp:64:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | return (cnt==a.size()?a:"");;
| ~~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |