Submission #938399

#TimeUsernameProblemLanguageResultExecution timeMemory
938399Ghulam_JunaidThree Friends (BOI14_friends)C++17
0 / 100
42 ms13632 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;
const ll base = 727;

ll k;
set<int> st;

void check(string s, string t, bool is_suff){
    int j = 0;
    int i = 0;
    int ind = t.size() - 1;
    for (; i < s.size() and j < t.size();){
        if (s[i] == t[j]){
            i++;
            j++;
        }
        else{
            ind = j;
            j++;
        }
    }

    if (i == s.size())
        st.insert(ind + k * is_suff);

    j = t.size() - 1;
    ind = 0;
    for (int i = s.size() - 1; i >= 0 and j >= 0;){
        if (s[i] == t[j]){
            i--;
            j--;
        }
        else{
            ind = j;
            j--;
        }
    }

    if (i == -1)
        st.insert(ind + k * is_suff);
}

int main(){
    ll n;
    string s;
    cin >> n >> s;

    if (n % 2 == 0){
        cout << "NOT POSSIBLE" << endl;
        return 0;
    }

    k = n / 2;
    ll poss = 0;

    string P, S;
    for (ll i = 0; i < k; i ++)
        P += s[i];
    for (ll i = k + 1; i < n; i ++)
        S += s[i];

    string ans;

    string Q = s[k] + S;
    check(P, Q, 1);
    if (st.size())
        ans = P;

    int prev = st.size();

    Q = P + s[k];
    check(S, Q, 0);
    if (st.size() - prev)
        ans = S;

    if (st.size() > 1)
        cout << "NOT UNIQUE" << endl;
    else if (st.size() == 0)
        cout << "NOT POSSIBLE" << endl;
    else
        cout << ans << endl;
}

Compilation message (stderr)

friends.cpp: In function 'void check(std::string, std::string, bool)':
friends.cpp:16:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for (; i < s.size() and j < t.size();){
      |            ~~^~~~~~~~~~
friends.cpp:16:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for (; i < s.size() and j < t.size();){
      |                             ~~^~~~~~~~~~
friends.cpp:27:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     if (i == s.size())
      |         ~~^~~~~~~~~~~
friends.cpp: In function 'int main()':
friends.cpp:58:8: warning: unused variable 'poss' [-Wunused-variable]
   58 |     ll poss = 0;
      |        ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...