Submission #727345

#TimeUsernameProblemLanguageResultExecution timeMemory
727345mdn2002Ekoeko (COCI21_ekoeko)C++14
110 / 110
238 ms2732 KiB
#include <bits/stdc++.h> using namespace std; long long n , is [200005] , ans , numm [31] , aa , bb; vector < int > l [31] , r [31]; string s , a , b; int main() { cin >> n >> s; for ( int i = 0 ; i < 2 * n ; i ++ ) { int c = s [i] - 'a'; numm [c] ++; } for ( int i = 0 ; i < 2 * n ; i ++ ) { int c = s [i] - 'a'; if ( l [c] . size () != numm [c] / 2 ) l [c] . push_back ( i ); else { r [c] . push_back ( i ); is [i] = 1; } } int num = 0; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( is [i] == 0 ) { num ++; a . push_back ( s [i] ); } else { ans += num; bb ++; b . push_back ( s [i] ); } } reverse ( a . begin () , a . end () ); reverse ( b . begin () , b . end () ); num = 0; for ( int i = n ; i < 2 * n ; i ++ ) { if ( is [i] == 1 ) { num ++; b . push_back ( s [i] ); } else { ans += num; aa ++; a . push_back ( s [i] ); } } ans += aa * bb; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { if ( a [i] == b [j] ) { for ( int k = j ; k > i ; k -- ) { ans ++; swap ( b [k] , b [ k - 1 ] ); } break; } } } cout << ans; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:17:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   17 |         if ( l [c] . size () != numm [c] / 2 ) l [c] . push_back ( i );
      |              ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...