Submission #982655

# Submission time Handle Problem Language Result Execution time Memory
982655 2024-05-14T15:15:25 Z SmuggingSpun JJOOII 2 (JOI20_ho_t2) C++14
1 / 100
178 ms 600 KB
#include<bits/stdc++.h>
#define taskname "B"
using namespace std;
template<class T>void minimize(T& a, T b){
	if(a > b){
		a = b;
	}
}
int n, k;
string s;
namespace sub1{
	void solve(){
		int m = 1 << n, ans = INT_MAX;
		string pat = string(k, 'J') + string(k, 'O') + string(k, 'I');
		for(int mask = 0; mask < m; mask++){
			string current = "";
			for(int i = 0; i < n; i++){
				if(1 << i & mask){
					current += s[i];
				}
			}
			if(current == pat){
				int l = 0, r = n - 1;
				while((1 << l & mask) == 0){
					l++;
				}
				while((1 << r & mask) == 0){
					r--;
				}
				int cnt = 0;
				for(int i = l; i <= r; i++){
					if((1 << i & mask) == 0){
						cnt++;
					}
				}
				minimize(ans, cnt);
			}
		}
		cout << (ans == INT_MAX ? -1 : ans);
	}
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(fopen(taskname".inp", "r")){
		freopen(taskname".inp", "r", stdin);
	}
	cin >> n >> k >> s;
	if(n <= 21){
		sub1::solve();
	}
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:45:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |   freopen(taskname".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 169 ms 348 KB Output is correct
4 Correct 170 ms 432 KB Output is correct
5 Correct 163 ms 344 KB Output is correct
6 Correct 163 ms 600 KB Output is correct
7 Correct 155 ms 344 KB Output is correct
8 Correct 142 ms 432 KB Output is correct
9 Correct 140 ms 348 KB Output is correct
10 Correct 142 ms 432 KB Output is correct
11 Correct 168 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 178 ms 432 KB Output is correct
14 Correct 165 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 169 ms 348 KB Output is correct
4 Correct 170 ms 432 KB Output is correct
5 Correct 163 ms 344 KB Output is correct
6 Correct 163 ms 600 KB Output is correct
7 Correct 155 ms 344 KB Output is correct
8 Correct 142 ms 432 KB Output is correct
9 Correct 140 ms 348 KB Output is correct
10 Correct 142 ms 432 KB Output is correct
11 Correct 168 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 178 ms 432 KB Output is correct
14 Correct 165 ms 344 KB Output is correct
15 Incorrect 0 ms 344 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 169 ms 348 KB Output is correct
4 Correct 170 ms 432 KB Output is correct
5 Correct 163 ms 344 KB Output is correct
6 Correct 163 ms 600 KB Output is correct
7 Correct 155 ms 344 KB Output is correct
8 Correct 142 ms 432 KB Output is correct
9 Correct 140 ms 348 KB Output is correct
10 Correct 142 ms 432 KB Output is correct
11 Correct 168 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 178 ms 432 KB Output is correct
14 Correct 165 ms 344 KB Output is correct
15 Incorrect 0 ms 344 KB Output isn't correct
16 Halted 0 ms 0 KB -