Submission #256557

# Submission time Handle Problem Language Result Execution time Memory
256557 2020-08-02T20:45:41 Z jainbot27 JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
23 ms 2052 KB
//Author: jainbot27
#pragma GCC optimize ("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;


#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ts to_string
#define ub upper_bound
#define lb lower_bound
#define ar array
#define FOR(x, y, z) for(int x = y; x < z; x++)
#define ROF(x, y, z) for(int x = y; x > z; x--)
#define all(x) x.begin(), x.end()


const char nl = '\n';
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using str = string;
using vpii = vector<pii>;
using vpll = vector<pll>;


str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
template<class A> str ts(complex<A> c) { 
	stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) { 
	str res = "{"; for(int i = 0;i < (int)v.size(); i++) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
	str res = ""; for(int i = 0; i < b.size(); i++) res += char('0'+b[i]);
	return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) { 
	bool fst = 1; str res = "{";
	for (const auto& x: v) {
		if (!fst) res += ", ";
		fst = 0; res += ts(x);
	}
	res += "}"; return res;
}
template<class A, class B> str ts(pair<A,B> p) {
	return "("+ts(p.f)+", "+ts(p.s)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << ts(h); if (sizeof...(t)) cerr << ", ";
	DBG(t...); }


#ifdef D 
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

const int N = 2e5 + 10;
int n, k;
string c;
vi pos[3];

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> k >> c;
	for(int i = 0; i < n; i++){
		if(c[i] == 'J'){
			pos[0].pb(i);
		}
		else if(c[i] == 'O'){
			pos[1].pb(i);
		}
		else{
			pos[2].pb(i);
		}
	}	
	int amt = 0;
	int ans = 2e9;
	for(int i = 0; i < n; i++){
		if(c[i] == 'J'){
			amt++;
		}
		if(amt >= k){
			int x = ub(pos[1].begin(), pos[1].end(), i) - pos[1].begin();
			dbg(i , x);
			if(x + k - 1< (int) pos[1].size()){
				int defin = pos[1][x + k - 1];
				int y = ub(all(pos[2]), defin) - pos[2].begin();
				dbg(defin , y);
				if(y + k - 1 < (int) pos[2].size()){
					int defin2 = pos[2][y + k - 1];
					int temp = (defin - pos[1][x] - (k-1)) + (defin2 - pos[2][y] - (k-1));
					int pos3 = pos[0][amt - k];
					dbg(defin2, temp, pos3);
					temp += (i - pos3 - (k - 1)) + (pos[1][x] - i - 1) + (pos[2][y] - defin - 1);
					ans = min(temp, ans);
				}
			} 
		}
	}
	if(ans == (int)2e9){
		cout << -1 << nl;
	}
	else{
		cout << ans << nl;
	}
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:94:14: warning: statement has no effect [-Wunused-value]
    dbg(i , x);
              ^
ho_t2.cpp:98:19: warning: statement has no effect [-Wunused-value]
     dbg(defin , y);
                   ^
ho_t2.cpp:103:29: warning: statement has no effect [-Wunused-value]
      dbg(defin2, temp, pos3);
                             ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 19 ms 1540 KB Output is correct
37 Correct 21 ms 1864 KB Output is correct
38 Correct 23 ms 2036 KB Output is correct
39 Correct 18 ms 2052 KB Output is correct
40 Correct 14 ms 2020 KB Output is correct
41 Correct 18 ms 2036 KB Output is correct
42 Correct 20 ms 1924 KB Output is correct
43 Correct 8 ms 1376 KB Output is correct
44 Correct 9 ms 1524 KB Output is correct
45 Correct 13 ms 2052 KB Output is correct
46 Correct 13 ms 1920 KB Output is correct
47 Correct 13 ms 2052 KB Output is correct
48 Correct 13 ms 2052 KB Output is correct
49 Correct 8 ms 1292 KB Output is correct
50 Correct 13 ms 1924 KB Output is correct
51 Correct 13 ms 1924 KB Output is correct
52 Correct 5 ms 1608 KB Output is correct
53 Correct 6 ms 1864 KB Output is correct
54 Correct 12 ms 2052 KB Output is correct
55 Correct 9 ms 2052 KB Output is correct
56 Correct 8 ms 2052 KB Output is correct