Submission #968776

# Submission time Handle Problem Language Result Execution time Memory
968776 2024-04-24T04:12:29 Z youssef_3breheem Three Friends (BOI14_friends) C++14
0 / 100
2 ms 348 KB
#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()){
        while(j<b.size()&&a[i]!=b[j]){
            cnt++,j++;
        }
        j++,i++;
    }
    return (cnt<=1?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;
    }
}

Compilation message

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()){
      |           ~^~~~~~~~~
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]){
      |               ~^~~~~~~~~
friends.cpp: In function 'int main()':
friends.cpp:87:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
friends.cpp:88:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -