답안 #753924

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
753924 2023-06-06T10:23:10 Z vjudge1 JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
1 ms 212 KB
//time 06.06.2023   23:00
#include <bits/stdc++.h>
#define ll long long
#define s second
#define f first

using namespace std;
const ll  N = 2e5+ 9;
const ll inf = 1e18;
const ll b_N = 2e5 + 9;

char a[N];

void solve(){
    int n,k;
    cin >> n >> k;

    int q = 0,w = 0,e = 0;

    for(int i = 1;i <= n;i++){
        cin >> a[i];
        if(a[i] == 'J' && q < k)q++;
        else if(q >= k && a[i] == 'O' && w < k)w++;
        else if(q >= k && a[i] == 'I' && e < k && w >= k)e++;
    }
    if(q < k || w < k || e < k)cout << "-1\n";
    else if(q == k && w == k && e == k && n % k == 0 && n / k == 3)cout << "0\n";
    else{
        int sum = n - (3 * k);
        if(a[1] == 'J' && a[n] == 'I');
        else if(a[1] == 'J' && a[n] != 'I')sum--;
        else if(a[1] != 'J' && a[n] == 'I')sum--;
        else sum -= 2;  
        cout << sum << '\n';
    }
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 //   freopen("herding.in","r",stdin);
 //   freopen("herding.out","w",stdout);
    solve();
}

Compilation message

ho_t2.cpp:37:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   37 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -