Submission #1023797

#TimeUsernameProblemLanguageResultExecution timeMemory
1023797AuroraJJOOII 2 (JOI20_ho_t2)C++14
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std;// Hello world arsaoshe aneru nesi isods const int mod = 1e9+7; const char nl = '\n'; typedef long long ll; const int N = 1e5 + 5 ; #define ff first #define ss second void void_code () { ll n; cin >> n;ll k; cin >> k; string s; cin >> s; ll l = - 1, r = n ; for ( int i =0 ;i < n; i ++ ) { if ( s [ i ] == 'J' ) { l = i ; break; } } for ( int i = n - 1; i >= 0 ; i -- ) { if ( s [ i ] == 'I' ) { r = i ; break; } } ll cnt = 0 ; ll oh = 1; ll gov = 0 ; vector < char > v ; for ( int i = l ;i < r + 1 ; i ++ ) { if ( oh == 1 ) { if ( s [ i ] == 'J' ){ cnt ++ ; v .push_back ( 'J' ) ; } if ( cnt == k ) { oh = 2; cnt = 0 ; } else if ( s [ i ] != 'J' ) { gov ++ ; } } else if ( oh == 2 ) { if ( s [ i ] == 'O' ){ cnt ++ ; v .push_back ( 'O' ) ; } if ( cnt == k ) { oh = 3; cnt = 0 ; } else if ( s [ i ] != 'O' ){ gov ++ ; } } else if ( oh == 3 ) { if ( s [ i ] == 'I' ){ cnt ++ ; v .push_back ( 'I' ) ; } if ( cnt == k ) { oh = 3; cnt = 0 ; break; } else if ( s [ i ] != 'I' ){ gov ++ ; } } } ll ch = r - l + 1; if ( ! v . empty () && k * 1ll * 3 == v . size () ) cout << gov ; //~ cout << ch - v . size (); else cout << -1 ; cout << nl << "gov = " << gov ; cout << nl; cout << "----------------" << nl; cout << gov ; cout << nl << l << " " << r << nl; cout << nl; for ( int i = 0 ;i < v . size (); i++ ) { cout << v [ i ] << " "; } cout << nl; for ( int i = l; i <= r ; i ++ ) { cout << s [ i ] << " "; } } signed main() { ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); int t = 1; //test //~ cin >> t; while (t--) void_code (); return 0; } //~ IIIOOOJIOOJOOIJJIJ //~ JIOOJOOIJJI //~ JOI //~ IIIOOOJIOOJOOIJJIJ

Compilation message (stderr)

ho_t2.cpp: In function 'void void_code()':
ho_t2.cpp:77:39: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |   if ( ! v . empty () && k * 1ll *  3 ==  v . size ()  )
      |                          ~~~~~~~~~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:89:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |   for ( int i = 0 ;i < v . size (); i++  ) {
      |                    ~~^~~~~~~~~~~~~
ho_t2.cpp:75:5: warning: unused variable 'ch' [-Wunused-variable]
   75 |  ll ch = r - l + 1;
      |     ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...