답안 #202301

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
202301 2020-02-15T07:56:57 Z amoo_safar JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
15 ms 5884 KB
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

ll J[N], O[N], I[N];
vector<ll> v;

ll calc(ll x){
	return I[O[J[x]]];
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n, k;
	cin >> n >> k;
	str s;
	cin >> s;
	J[n] = n;
	O[n] = n;
	I[n] = n;
	v.clear();
	for(int i = n - 1; i >= 0; i--){
		if(s[i] == 'J') v.pb(i);
		J[i] = (v.size() < k ? n : v[v.size() - k]);
	}
	v.clear();
	for(int i = n - 1; i >= 0; i--){
		if(s[i] == 'O') v.pb(i);
		O[i] = (v.size() < k ? n : v[v.size() - k]);
	}
	v.clear();
	for(int i = n - 1; i >= 0; i--){
		if(s[i] == 'I') v.pb(i);
		I[i] = (v.size() < k ? n : v[v.size() - k]);
	}
	if(calc(0) == n) return cout << "-1\n", 0;
	ll ans = n;
	for(int i = 0; i < n; i++){
		if(calc(i) == n) break;
		ans = min(ans, (calc(i) - i + 1) - 3*k);
	}
	cout << ans;
	return 0;
}
/*
5
4 7 9 10 11 12
3 5 7 9 11
*/

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:40:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   J[i] = (v.size() < k ? n : v[v.size() - k]);
           ~~~~~~~~~^~~
ho_t2.cpp:45:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   O[i] = (v.size() < k ? n : v[v.size() - k]);
           ~~~~~~~~~^~~
ho_t2.cpp:50:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   I[i] = (v.size() < k ? n : v[v.size() - k]);
           ~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 4 ms 380 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 4 ms 380 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 5 ms 504 KB Output is correct
17 Correct 5 ms 504 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 504 KB Output is correct
20 Correct 5 ms 504 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 504 KB Output is correct
25 Correct 5 ms 504 KB Output is correct
26 Correct 5 ms 504 KB Output is correct
27 Correct 7 ms 632 KB Output is correct
28 Correct 6 ms 504 KB Output is correct
29 Correct 5 ms 504 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 508 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 4 ms 380 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 5 ms 504 KB Output is correct
17 Correct 5 ms 504 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 504 KB Output is correct
20 Correct 5 ms 504 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 504 KB Output is correct
25 Correct 5 ms 504 KB Output is correct
26 Correct 5 ms 504 KB Output is correct
27 Correct 7 ms 632 KB Output is correct
28 Correct 6 ms 504 KB Output is correct
29 Correct 5 ms 504 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 508 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 11 ms 5500 KB Output is correct
37 Correct 12 ms 5880 KB Output is correct
38 Correct 15 ms 5880 KB Output is correct
39 Correct 13 ms 5880 KB Output is correct
40 Correct 12 ms 5880 KB Output is correct
41 Correct 12 ms 5880 KB Output is correct
42 Correct 12 ms 5880 KB Output is correct
43 Correct 9 ms 4016 KB Output is correct
44 Correct 10 ms 4604 KB Output is correct
45 Correct 12 ms 5880 KB Output is correct
46 Correct 11 ms 5880 KB Output is correct
47 Correct 12 ms 5880 KB Output is correct
48 Correct 12 ms 5884 KB Output is correct
49 Correct 9 ms 4092 KB Output is correct
50 Correct 14 ms 5880 KB Output is correct
51 Correct 11 ms 5880 KB Output is correct
52 Correct 11 ms 5756 KB Output is correct
53 Correct 12 ms 5880 KB Output is correct
54 Correct 9 ms 5880 KB Output is correct
55 Correct 9 ms 5880 KB Output is correct
56 Correct 10 ms 5880 KB Output is correct