Submission #398825

#TimeUsernameProblemLanguageResultExecution timeMemory
398825YaserFaisalThree Friends (BOI14_friends)C++14
35 / 100
1069 ms18076 KiB
#include <bits/stdc++.h> using namespace std ; //#define int long long int MOD = 1e9+7 ; int freq[200] ; vector < int > v[200] ; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n ; cin >> n ; string s ; cin >> s ; for ( int i = 0 ; i < n ; i++ ) { freq[s[i]]++ ; v[s[i]].push_back(i) ; } char c ; int odd = 0 ; for ( int i = 'A' ; i <= 'Z' ; i++ ) { if ( (freq[i] % 2) == 1 ) { odd++ ; c = i ; } } if ( odd != 1 || (n % 2) == 0 ) { cout << "NOT POSSIBLE" ; return 0 ; } string ans = "-" ; for ( int i = 0 ; i < v[c].size() ; i++ ) { int x = v[c][i] ; string a , b ; int m = n/2 ; if ( x == m ) { a = s.substr(0,m) ; b = s.substr(m+1) ; } if ( x < m ) { a = s.substr(0,x) + s.substr(x+1,m-x) ; b = s.substr(m+1) ; } if ( x > m ) { a = s.substr(0,m) ; b = s.substr(m,x-m) + s.substr(x+1) ; } //cout << x << " " << a << " " << b << " " << endl ; if ( a == b ) { if ( a == ans ) continue ; else if ( ans == "-" ) ans = a ; else { cout << "NOT UNIQUE" << endl ; return 0 ; } } } if ( ans == "-" ) ans = "NOT POSSIBLE" ; cout << ans ; }

Compilation message (stderr)

friends.cpp: In function 'int32_t main()':
friends.cpp:17:18: warning: array subscript has type 'char' [-Wchar-subscripts]
   17 |         freq[s[i]]++ ;
      |                  ^
friends.cpp:18:15: warning: array subscript has type 'char' [-Wchar-subscripts]
   18 |         v[s[i]].push_back(i) ;
      |               ^
friends.cpp:36:29: warning: array subscript has type 'char' [-Wchar-subscripts]
   36 |     for ( int i = 0 ; i < v[c].size() ; i++ )
      |                             ^
friends.cpp:36:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for ( int i = 0 ; i < v[c].size() ; i++ )
      |                       ~~^~~~~~~~~~~~~
friends.cpp:38:19: warning: array subscript has type 'char' [-Wchar-subscripts]
   38 |         int x = v[c][i] ;
      |                   ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...