Submission #203080

# Submission time Handle Problem Language Result Execution time Memory
203080 2020-02-19T09:25:29 Z _7_7_ JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
29 ms 6528 KB
#include <bits/stdc++.h>                                           
 
//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 2e5 + 11;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;


int n, k, a[N];
string s;
vi g[N];



main () {
	cin >> n >> k >> s;
	forn (i, 0, n - 1)
		if (s[i] == 'J')
			g[0].pb(i);
		else if (s[i] == 'O')
			g[1].pb(i);
		else
			g[2].pb(i);

	if (sz(g[0]) < k || sz(g[1]) < k || sz(g[2]) < k) {
		cout << -1;
		return 0;
	}

	
	int ans = inf;
	forn (i, 0, sz(g[0]) - k) {
		int j = lower_bound(all(g[1]), g[0][i + k - 1]) - g[1].begin();
		if (j + k - 1 >= sz(g[1]))
			break;
		int x = lower_bound(all(g[2]), g[1][j + k - 1]) - g[2].begin();
		if (x + k - 1 >= sz(g[2]))
			break;
		ans = min(ans, g[2][x + k - 1] - g[0][i] + 1 - 3*k);
	}

	if (ans == inf)
		ans = -1;
	cout << ans << endl;
	return 0;			
}

Compilation message

ho_t2.cpp:47:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4984 KB Output is correct
2 Correct 7 ms 4984 KB Output is correct
3 Correct 8 ms 4984 KB Output is correct
4 Correct 8 ms 4984 KB Output is correct
5 Correct 8 ms 4984 KB Output is correct
6 Correct 8 ms 4984 KB Output is correct
7 Correct 7 ms 4984 KB Output is correct
8 Correct 8 ms 4984 KB Output is correct
9 Correct 8 ms 4984 KB Output is correct
10 Correct 8 ms 4984 KB Output is correct
11 Correct 7 ms 4988 KB Output is correct
12 Correct 8 ms 4984 KB Output is correct
13 Correct 8 ms 4984 KB Output is correct
14 Correct 7 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4984 KB Output is correct
2 Correct 7 ms 4984 KB Output is correct
3 Correct 8 ms 4984 KB Output is correct
4 Correct 8 ms 4984 KB Output is correct
5 Correct 8 ms 4984 KB Output is correct
6 Correct 8 ms 4984 KB Output is correct
7 Correct 7 ms 4984 KB Output is correct
8 Correct 8 ms 4984 KB Output is correct
9 Correct 8 ms 4984 KB Output is correct
10 Correct 8 ms 4984 KB Output is correct
11 Correct 7 ms 4988 KB Output is correct
12 Correct 8 ms 4984 KB Output is correct
13 Correct 8 ms 4984 KB Output is correct
14 Correct 7 ms 4984 KB Output is correct
15 Correct 8 ms 4984 KB Output is correct
16 Correct 9 ms 5112 KB Output is correct
17 Correct 9 ms 4984 KB Output is correct
18 Correct 8 ms 5112 KB Output is correct
19 Correct 8 ms 4984 KB Output is correct
20 Correct 8 ms 4984 KB Output is correct
21 Correct 8 ms 5112 KB Output is correct
22 Correct 8 ms 5112 KB Output is correct
23 Correct 8 ms 4984 KB Output is correct
24 Correct 8 ms 4984 KB Output is correct
25 Correct 8 ms 4988 KB Output is correct
26 Correct 10 ms 4984 KB Output is correct
27 Correct 8 ms 4984 KB Output is correct
28 Correct 8 ms 4984 KB Output is correct
29 Correct 8 ms 4984 KB Output is correct
30 Correct 8 ms 4984 KB Output is correct
31 Correct 8 ms 4984 KB Output is correct
32 Correct 8 ms 4984 KB Output is correct
33 Correct 8 ms 4984 KB Output is correct
34 Correct 8 ms 4984 KB Output is correct
35 Correct 8 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4984 KB Output is correct
2 Correct 7 ms 4984 KB Output is correct
3 Correct 8 ms 4984 KB Output is correct
4 Correct 8 ms 4984 KB Output is correct
5 Correct 8 ms 4984 KB Output is correct
6 Correct 8 ms 4984 KB Output is correct
7 Correct 7 ms 4984 KB Output is correct
8 Correct 8 ms 4984 KB Output is correct
9 Correct 8 ms 4984 KB Output is correct
10 Correct 8 ms 4984 KB Output is correct
11 Correct 7 ms 4988 KB Output is correct
12 Correct 8 ms 4984 KB Output is correct
13 Correct 8 ms 4984 KB Output is correct
14 Correct 7 ms 4984 KB Output is correct
15 Correct 8 ms 4984 KB Output is correct
16 Correct 9 ms 5112 KB Output is correct
17 Correct 9 ms 4984 KB Output is correct
18 Correct 8 ms 5112 KB Output is correct
19 Correct 8 ms 4984 KB Output is correct
20 Correct 8 ms 4984 KB Output is correct
21 Correct 8 ms 5112 KB Output is correct
22 Correct 8 ms 5112 KB Output is correct
23 Correct 8 ms 4984 KB Output is correct
24 Correct 8 ms 4984 KB Output is correct
25 Correct 8 ms 4988 KB Output is correct
26 Correct 10 ms 4984 KB Output is correct
27 Correct 8 ms 4984 KB Output is correct
28 Correct 8 ms 4984 KB Output is correct
29 Correct 8 ms 4984 KB Output is correct
30 Correct 8 ms 4984 KB Output is correct
31 Correct 8 ms 4984 KB Output is correct
32 Correct 8 ms 4984 KB Output is correct
33 Correct 8 ms 4984 KB Output is correct
34 Correct 8 ms 4984 KB Output is correct
35 Correct 8 ms 4984 KB Output is correct
36 Correct 26 ms 6144 KB Output is correct
37 Correct 29 ms 6340 KB Output is correct
38 Correct 28 ms 6512 KB Output is correct
39 Correct 26 ms 6528 KB Output is correct
40 Correct 22 ms 6496 KB Output is correct
41 Correct 26 ms 6512 KB Output is correct
42 Correct 27 ms 6400 KB Output is correct
43 Correct 17 ms 5888 KB Output is correct
44 Correct 18 ms 6000 KB Output is correct
45 Correct 20 ms 6528 KB Output is correct
46 Correct 21 ms 6396 KB Output is correct
47 Correct 21 ms 6528 KB Output is correct
48 Correct 21 ms 6524 KB Output is correct
49 Correct 16 ms 5768 KB Output is correct
50 Correct 22 ms 6400 KB Output is correct
51 Correct 21 ms 6400 KB Output is correct
52 Correct 20 ms 6088 KB Output is correct
53 Correct 21 ms 6332 KB Output is correct
54 Correct 21 ms 6524 KB Output is correct
55 Correct 19 ms 6528 KB Output is correct
56 Correct 20 ms 6520 KB Output is correct