답안 #1023712

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1023712 2024-07-15T05:16:34 Z vjudge1 JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
0 ms 348 KB
#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 ;
	ll  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 res = 0 ;
	ll cnt = 0 ; 
	ll ans = 1 ;
	ll ch = 0 ;
	vector < char > v = { 'J' , 'O' , 'I' };
	for ( int i = l ; i <= r ; i ++ ) {
		for ( int j = i + 1 ; j <= r ; j ++ ) {
			if ( ans != k ) {
				if ( s [ j ] == v [ ch ]  ) {
					ans ++ ;
				}
				else {
					cnt ++ ;
				}
			}
			if ( ans == k ) {
				i = j ;
				res = cnt ;
				cnt = 0 ;
				ans = 1;
				ch ++ ;
				j = r ;
			}
		}
	}
	cout << res ;
}


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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -