Submission #887971

# Submission time Handle Problem Language Result Execution time Memory
887971 2023-12-15T16:00:27 Z hariaakas646 JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
9 ms 3564 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(x) scanf("%d", &x)
#define sclld(x) scanf("%lld", &x)
#define frange(i, n) for(int i=0; i<n; i++)
#define forr(i, l, r) for(int i=l; i<r; i++)
#define all(vec) vec.begin(), vec.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second

typedef long long lli;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<lli> vll;
typedef vector<vi> vvi;

void usaco() {
	freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
}

int main() {
	// usaco();
	int n, k;
	scd(n);
	scd(k);

	string str;
	cin >> str;

	vi veci(n+1, -1), veco(n+1, -1), vecj(n+1, -1);

	int l = 0;
	int r = 0;
	int c = 0;
	if(str[l] == 'I') c++;
	bool done = false;
	while(l < n) {

		while(c < k) {
			r++;
			if(r >= n) {
				forr(i, l, n) veci[i] = -1;
				done = true;
				break;
			}
			if(str[r] == 'I') c++;
		}
		if(done) break;

		if(c == k) {
			veci[l] = r;
			if(str[l] == 'I') c--;
			l++;
		}
	}

	l = 0;
	r = 0;
	c = 0;
	if(str[l] == 'O') c++;
	done = false;
	while(l < n) {

		while(c < k) {
			r++;
			if(r >= n) {
				forr(i, l, n) veco[i] = -1;
				done = true;
				break;
			}
			if(str[r] == 'O') c++;
		}
		if(done) break;

		if(c == k) {
			veco[l] = r;
			if(str[l] == 'O') c--;
			l++;
		}
	}

	l = 0;
	r = 0;
	c = 0;
	if(str[l] == 'J') c++;
	done = false;
	while(l < n) {

		while(c < k) {
			r++;
			if(r >= n) {
				forr(i, l, n) vecj[i] = -1;
				done = true;
				break;
			}
			if(str[r] == 'J') c++;
		}
		if(done) break;

		if(c == k) {
			vecj[l] = r;
			if(str[l] == 'J') c--;
			l++;
		}
	}

	for(int i=n-1; i>=0; i--) {
		if(veco[i] != -1) {
			int id = veco[i];
			if(veci[id+1] != -1) {
				veco[i] = veci[id+1];
			}
			else veco[i] = -1;
		}
	}

	for(int i=n-1; i>=0; i--) {
		if(vecj[i] != -1) {
			int id = vecj[i];
			if(veco[id+1] != -1) {
				vecj[i] = veco[id+1];
			}
			else vecj[i] = -1;
		}
	}

	int out = -1;

	frange(i, n) {
		if(vecj[i] != -1) {
			int v = vecj[i] - i + 1 - 3 * k;
			if(out == -1) out = v;
			out = min(out, v);
		}
	}

	printf("%d", out);
}

Compilation message

ho_t2.cpp: In function 'void usaco()':
ho_t2.cpp:23:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |  freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(x) scanf("%d", &x)
      |                ~~~~~^~~~~~~~~~
ho_t2.cpp:29:2: note: in expansion of macro 'scd'
   29 |  scd(n);
      |  ^~~
ho_t2.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(x) scanf("%d", &x)
      |                ~~~~~^~~~~~~~~~
ho_t2.cpp:30:2: note: in expansion of macro 'scd'
   30 |  scd(k);
      |  ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 432 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 432 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 484 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 432 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 432 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 432 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 484 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 432 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 432 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 8 ms 3052 KB Output is correct
37 Correct 8 ms 3308 KB Output is correct
38 Correct 8 ms 3188 KB Output is correct
39 Correct 9 ms 3300 KB Output is correct
40 Correct 9 ms 3564 KB Output is correct
41 Correct 9 ms 3152 KB Output is correct
42 Correct 9 ms 3316 KB Output is correct
43 Correct 5 ms 2132 KB Output is correct
44 Correct 6 ms 2700 KB Output is correct
45 Correct 8 ms 3308 KB Output is correct
46 Correct 8 ms 3308 KB Output is correct
47 Correct 8 ms 3304 KB Output is correct
48 Correct 8 ms 3308 KB Output is correct
49 Correct 5 ms 2284 KB Output is correct
50 Correct 9 ms 3196 KB Output is correct
51 Correct 8 ms 3312 KB Output is correct
52 Correct 7 ms 3160 KB Output is correct
53 Correct 6 ms 3320 KB Output is correct
54 Correct 5 ms 3320 KB Output is correct
55 Correct 5 ms 3052 KB Output is correct
56 Correct 7 ms 3312 KB Output is correct