답안 #581604

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581604 2022-06-22T20:46:06 Z Metal_Sonic JJOOII 2 (JOI20_ho_t2) C++17
13 / 100
2000 ms 1116 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sz(x) (int)(x).size()
#define all(x) x.begin() , x.end()
void setIO(string name = "") {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    if(sz(name)){
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}
int n,k;
string s;
int solve(int j){
    int cntj = 0, cnto = 0, cnti = 0;
    int garbage = 0;
    while(cntj != k && j < n){
        if(s[j] == 'J')cntj++;
        else garbage++;
        j++;
    }
    while(cnto != k && j < n){
        if(s[j] == 'O')cnto++;
        else garbage++;
        j++;
    }
    while(cnti != k && j < n){
        if(s[j] == 'I')cnti++;
        else garbage++;
        j++;
    }
    if(cntj == k && cnto == k && cnti == k)return garbage;
    return 5000;
}
void run_test_case(){
    cin>>n>>k>>s;
    vector<int>J;
    for(int i = 0; i < n; i++){
        if(s[i]=='J')J.push_back(i);
    }
    int ans = 5000;
    for(auto it : J){
        ans = min(ans,solve(it));
    }
        cout<<(ans == 5000 ? -1 : ans);
}
int main() {
    setIO();
    int T = 1;
    while(T--){
        run_test_case();
    }
    return 0;
}

Compilation message

ho_t2.cpp: In function 'void setIO(std::string)':
ho_t2.cpp:9:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |         freopen((name+".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:10:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         freopen((name+".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 3 ms 212 KB Output is correct
25 Correct 4 ms 340 KB Output is correct
26 Correct 2 ms 212 KB Output is correct
27 Correct 3 ms 332 KB Output is correct
28 Correct 2 ms 212 KB Output is correct
29 Correct 2 ms 212 KB Output is correct
30 Correct 3 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 3 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 2 ms 212 KB Output is correct
35 Correct 2 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 3 ms 212 KB Output is correct
25 Correct 4 ms 340 KB Output is correct
26 Correct 2 ms 212 KB Output is correct
27 Correct 3 ms 332 KB Output is correct
28 Correct 2 ms 212 KB Output is correct
29 Correct 2 ms 212 KB Output is correct
30 Correct 3 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 3 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 2 ms 212 KB Output is correct
35 Correct 2 ms 212 KB Output is correct
36 Correct 4 ms 864 KB Output is correct
37 Correct 4 ms 1116 KB Output is correct
38 Correct 4 ms 1116 KB Output is correct
39 Execution timed out 2081 ms 1116 KB Time limit exceeded
40 Halted 0 ms 0 KB -