Submission #398756

#TimeUsernameProblemLanguageResultExecution timeMemory
398756katwamiawThree Friends (BOI14_friends)C++14
35 / 100
1083 ms4072 KiB
#include<bits/stdc++.h>
using namespace std ;

//it ain't much but it's honest work

int a[27] ;
char c[27] ;
vector<int>v ;
vector<string>q ;
set<string>z ;
int n ;
string s ;

void something(int x){
    string ans ;
    //cout << x << endl ;
    for(int i=0 ; i<n/2 ; i++){
        //if(i==x) continue ;
        int r=i , t=(n/2)+i ;
        if(r>=x) r++ ;
        if(t>=x) t++ ;
        if(s[r]==s[t]){
            ans+=s[r] ;
            //cout << 8 ;
        }
        else{
            break ;
        }
    }
    if(ans.size()==n/2){
        q.push_back(ans) ;
        z.insert(ans) ;
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    cin >> n >> s ;
    for(int i=0 ; i<n ; i++){
        a[(s[i]-'0')-17]++ ;
    }
    int k=-1 , g=0 ;
    for(int i=0 ; i<26 ; i++){
        if(a[i]%2){
            k=i ;
            g++ ;
        }
    }
    if(g>1||k==-1){
        cout << "NOT POSSIBLE" ;
        return 0 ;
    }

    for(int i=0 ; i<n ; i++){
        if(((s[i]-'0')-17)==k){
            v.push_back(i) ;
            //cout << s[i] ;
        }
    }

    for(int i=0 ; i<v.size() ; i++){
        something(v[i]) ;
    }
    if(z.size()==0){
        cout << "NOT POSSIBLE" ;
    }
    else if(z.size()>1){
        cout << "NOT UNIQUE" ;
    }
    else{
        cout << q[0] ;
    }
}

Compilation message (stderr)

friends.cpp: In function 'void something(int)':
friends.cpp:30:18: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   30 |     if(ans.size()==n/2){
      |        ~~~~~~~~~~^~~~~
friends.cpp: In function 'int main()':
friends.cpp:62:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int i=0 ; i<v.size() ; i++){
      |                   ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...