Submission #1093558

# Submission time Handle Problem Language Result Execution time Memory
1093558 2024-09-27T03:21:32 Z IBory Flip it and Stick it (CCO23_day2problem1) C++17
18 / 25
5 ms 1384 KB
#include <bits/stdc++.h>
using namespace std;

int Count(string S, string T) {
	int ret = 0;
	for (int i = 0; i + T.size() <= S.size(); ++i) {
		ret += (S.substr(i, T.size()) == T);
	}
	return ret;
}

int Solve(string S, string T) {
	if (T.size() == 1) return (S.find(T) == string::npos ? 0 : -1);

	if (T == "011" || T == "100") {
		reverse(S.begin(), S.end());
		reverse(T.begin(), T.end());
	}
	if (T[0] == '1') {
		for (char& c : S) c ^= 1;
		for (char& c : T) c ^= 1;
	}

	int zero = 0;
	for (char c : S) zero += (c == '0');

	if (T == "01") return Count(S, T);
	if (T == "00") {
		int lim = (S.size() + 1) / 2;
		if (lim < zero) return -1;
		return Count(S, T);
	}

	if (T == "001") return Count(S, T);
	if (T == "010") return (Count(S, T) + 1) / 2;
	if (T == "000") {
		int lim = (int)S.size() - (int)S.size() / 3;
		if (lim < zero) return -1;
		return Count(S, T);
	}
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	string S, T;
	cin >> S >> T;
	cout << Solve(S, T);
	return 0;
}

Compilation message

Main.cpp: In function 'int Solve(std::string, std::string)':
Main.cpp:41:1: warning: control reaches end of non-void function [-Wreturn-type]
   41 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 1028 KB Output is correct
4 Correct 1 ms 992 KB Output is correct
5 Correct 1 ms 996 KB Output is correct
6 Correct 1 ms 996 KB Output is correct
7 Correct 1 ms 1120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 3 ms 1252 KB Output is correct
7 Correct 3 ms 1248 KB Output is correct
8 Correct 3 ms 1252 KB Output is correct
9 Correct 3 ms 1252 KB Output is correct
10 Correct 3 ms 1252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 3 ms 1252 KB Output is correct
7 Correct 3 ms 1248 KB Output is correct
8 Correct 3 ms 1252 KB Output is correct
9 Correct 3 ms 1252 KB Output is correct
10 Correct 3 ms 1252 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 3 ms 1252 KB Output is correct
21 Correct 3 ms 1248 KB Output is correct
22 Correct 3 ms 1252 KB Output is correct
23 Correct 3 ms 1252 KB Output is correct
24 Correct 2 ms 1240 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 3 ms 1252 KB Output is correct
27 Correct 3 ms 1252 KB Output is correct
28 Correct 1 ms 996 KB Output is correct
29 Correct 3 ms 1244 KB Output is correct
30 Correct 3 ms 1252 KB Output is correct
31 Correct 2 ms 1252 KB Output is correct
32 Correct 2 ms 1240 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 3 ms 1252 KB Output is correct
8 Correct 3 ms 1252 KB Output is correct
9 Correct 3 ms 1252 KB Output is correct
10 Correct 3 ms 1252 KB Output is correct
11 Correct 3 ms 1252 KB Output is correct
12 Correct 3 ms 1252 KB Output is correct
13 Correct 3 ms 1252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 3 ms 1280 KB Output is correct
11 Correct 3 ms 1252 KB Output is correct
12 Correct 3 ms 1252 KB Output is correct
13 Correct 3 ms 1252 KB Output is correct
14 Correct 3 ms 1252 KB Output is correct
15 Correct 4 ms 1280 KB Output is correct
16 Correct 3 ms 1252 KB Output is correct
17 Correct 2 ms 1252 KB Output is correct
18 Correct 3 ms 1252 KB Output is correct
19 Correct 2 ms 1252 KB Output is correct
20 Correct 3 ms 1248 KB Output is correct
21 Correct 5 ms 1380 KB Output is correct
22 Correct 4 ms 1384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 3 ms 1252 KB Output is correct
8 Correct 3 ms 1252 KB Output is correct
9 Correct 3 ms 1252 KB Output is correct
10 Correct 3 ms 1252 KB Output is correct
11 Correct 3 ms 1252 KB Output is correct
12 Correct 3 ms 1252 KB Output is correct
13 Correct 3 ms 1252 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 3 ms 1280 KB Output is correct
24 Correct 3 ms 1252 KB Output is correct
25 Correct 3 ms 1252 KB Output is correct
26 Correct 3 ms 1252 KB Output is correct
27 Correct 3 ms 1252 KB Output is correct
28 Correct 4 ms 1280 KB Output is correct
29 Correct 3 ms 1252 KB Output is correct
30 Correct 2 ms 1252 KB Output is correct
31 Correct 3 ms 1252 KB Output is correct
32 Correct 2 ms 1252 KB Output is correct
33 Correct 3 ms 1248 KB Output is correct
34 Correct 5 ms 1380 KB Output is correct
35 Correct 4 ms 1384 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Incorrect 0 ms 348 KB Output isn't correct
38 Halted 0 ms 0 KB -