답안 #1023731

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1023731 2024-07-15T05:33:53 Z vjudge1 JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
1 ms 600 KB
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define ROF(i,m,n) for(int i=m;i<=n;i++)
#define vi vector<int>
#define pb push_back
#define alle(a) a.begin(),a.end()
#define rall(n) rbegin(n),rend(n)
#define int long long
#define vecs vector<int> 
#define ll long long
#define ss second 
#define ff first
const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int N = 2005;

void solve(){
    int n, k;
    cin>>n>>k;
    string s;
    cin>>s;
    int a, b;
    int j1 = 0, o = 0, m = INF,y = 0;
    int i = 0, j = n - 1;
    while(i < n){
        j1 = 0;
        o = 0;
        if(s[i] == 'J'){
            while(j > i){
                if(s[j] == 'I'){
                    int c = k;
                    int i2 = i, j2 = j, o = 0;
                    for(int f = i;f < j;f++){
                        if(s[f] == 'J'){
                            j1++;
                        }
                        if(j1 >= k){
                            i2 = f;
                            break;
                        }
                    }
                    int h = 0;
                    for(int f = j;f >= i;f--){
                        if(s[f] == 'I'){
                            
                            h = h + 1;
                        }
                        if(h == c){
                            j2 = f;
                            break;
                        }
                    }
                    if(j2 == j||i2 == i){
                        break;
                    }
                    o = 0;
                    bool t = false;
                    for(int f = i2;f <= j2;f++){
                        if(s[f] == 'O'){
                            o++;
                        }
                        if(o >= k){
                            t = true;
                            break; 
                        }
                    }
                    if(t){
                        m = min((j - i + 1) - 3 * k,m);
                    }
                }
                j--;
            }
        }
        i++;

    }
    if(m == INF){
        cout<<"-1";
    }
    else{
        cout<<m;
    }

}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    while (t--) {
        solve();
    }
    return 0;
}

Compilation message

ho_t2.cpp: In function 'void solve()':
ho_t2.cpp:26:9: warning: unused variable 'a' [-Wunused-variable]
   26 |     int a, b;
      |         ^
ho_t2.cpp:26:12: warning: unused variable 'b' [-Wunused-variable]
   26 |     int a, b;
      |            ^
ho_t2.cpp:27:17: warning: variable 'o' set but not used [-Wunused-but-set-variable]
   27 |     int j1 = 0, o = 0, m = INF,y = 0;
      |                 ^
ho_t2.cpp:27:32: warning: unused variable 'y' [-Wunused-variable]
   27 |     int j1 = 0, o = 0, m = INF,y = 0;
      |                                ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -