Submission #230069

# Submission time Handle Problem Language Result Execution time Memory
230069 2020-05-08T05:16:51 Z AMO5 JJOOII 2 (JOI20_ho_t2) C++
1 / 100
2000 ms 384 KB
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int const mxn=2e5+5;
vi dp[3]; //JOI,pos

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n,k; string s;
	cin >> n >> k >> s;
	dp[0].emplace_back(0);
	dp[1].emplace_back(0);
	dp[2].emplace_back(0);
	for(int i=0; i<n; i++){
		dp[0].emplace_back(dp[0].back()+(s[i]=='J'?1:0));
		dp[1].emplace_back(dp[1].back()+(s[i]=='O'?1:0));
		dp[2].emplace_back(dp[2].back()+(s[i]=='I'?1:0));
	}
	int ans=1e9;
	int JJ = dp[0][n], OO = dp[1][n], II = dp[2][n];
	for(int j=JJ; j>=k; j--){
		int posj = lower_bound(all(dp[0]),j)-dp[0].begin();
		int cnto = dp[1][posj];
		for(int o=OO; o>=cnto+k; o--){
			int poso = lower_bound(all(dp[1]),o)-dp[1].begin();
			int cnti = dp[2][poso];
			for(int i=II; i>=cnti+k; i--){
				int posi = lower_bound(all(dp[2]),i)-dp[2].begin();
				int st = dp[0][posj]-k+1;
				int posini = lower_bound(all(dp[0]),st)-dp[0].begin();
				int len = posi-posini+1;
				int cnt = len-k*3;
				ans = min(ans,cnt);
			}
		}
	}
	if(ans==1e9)ans=-1;
	cout << ans << endl;
}	
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Execution timed out 2082 ms 384 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Execution timed out 2082 ms 384 KB Time limit exceeded
16 Halted 0 ms 0 KB -