답안 #535297

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
535297 2022-03-10T01:09:35 Z Koying JJOOII 2 (JOI20_ho_t2) C++14
1 / 100
2000 ms 2532 KB
#include <bits/stdc++.h>
#define int long long
#pragma GCC optimize("Ofast")
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define cmax(a, b) a = max(a, b)
#define cmin(a, b) a = min(a, b)
#define MEM(x, n) memset(x, n, sizeof(x))
#define pii pair<int, int>
#define pdd pair<double, double>
#define DB(x) cerr << #x << " " << x << endl;
#define endl "\n"
#define Koying ios::sync_with_stdio(0), cin.tie(0)
#define lowbit(x) x &(-x)
const int INF = 0x3f3f3f3f3f3f3f3f;
using namespace std;

#define MAXN 200005

int n, k;
string s;

void sol() {
    cin >> n >> k;
    cin >> s;
    int mn = INF;
    DB(s);
    for (int i = 0; i <= n - k * 3; i++) {
        int a, b, c;
        a = b = c = 0;
        for (int j = i; j < n; j++) {
            if (a < k) {
                a += (s[j] == 'J');
                DB(a);
            }
            else if (b < k) {
                b += s[j] == 'O';
            }
            else if (c < k) {
                c += s[j] == 'I';
            }
            if (a == k && b == k && c == k) {
                cmin(mn, j - i + 1);
                break;
            }
        }
        //cout << a << " " << b << " " << c << endl;
    }
    if (mn == INF) {
        cout << -1 << endl;
        return;
    }
    cout << mn - 3 * k << endl;
}

signed main()
{
    Koying;
    int t = 1;
    //cin >> t;
    sol();
    return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:59:9: warning: unused variable 't' [-Wunused-variable]
   59 |     int t = 1;
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 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 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 40 ms 324 KB Output is correct
16 Correct 44 ms 340 KB Output is correct
17 Correct 46 ms 340 KB Output is correct
18 Execution timed out 2076 ms 2532 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 40 ms 324 KB Output is correct
16 Correct 44 ms 340 KB Output is correct
17 Correct 46 ms 340 KB Output is correct
18 Execution timed out 2076 ms 2532 KB Time limit exceeded
19 Halted 0 ms 0 KB -