답안 #1093611

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1093611 2024-09-27T06:45:50 Z IBory Flip it and Stick it (CCO23_day2problem1) C++17
18 / 25
37 ms 10212 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);
	int N = S.size();

	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 = (N + 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 = N - N / 3;
		if (lim < zero) return -1;
		
		int ret = 0;
		for (int t = 0; t < 2; ++t) {
			for (int i = 0; i + 3 <= N; ++i) {
				if (S.back() == '0') break;
				if (S[i] == '1' || S[i + 1] == '1' || S[i + 2] == '1') continue;
				ret++;
				reverse(S.begin() + i + 2, S.end());
				break;
			}
			reverse(S.begin(), S.end());
		}

		multiset<int> X;
		int cur = 0;
		for (char c : S) {
			if (c == '0') cur++;
			else {
				X.insert(cur);
				cur = 0;
			}
		}
		X.insert(cur);

		while (3 <= *X.rbegin()) {
			ret++;
			int a = *X.begin(), b = *X.rbegin();
			if (b == 3 && a == 0) {
				if (X.find(1) != X.end()) a = 1;
			}
			int n = min(2 - a, b - 2);
			X.erase(X.find(a));
			X.erase(X.find(b));
			X.insert(a + n);
			X.insert(b - n);
		}

		return ret;
	}
}

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:79:1: warning: control reaches end of non-void function [-Wreturn-type]
   79 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 988 KB Output is correct
4 Correct 1 ms 996 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 996 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
6 Correct 2 ms 1236 KB Output is correct
7 Correct 3 ms 1252 KB Output is correct
8 Correct 2 ms 1284 KB Output is correct
9 Correct 2 ms 1252 KB Output is correct
10 Correct 2 ms 1240 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
6 Correct 2 ms 1236 KB Output is correct
7 Correct 3 ms 1252 KB Output is correct
8 Correct 2 ms 1284 KB Output is correct
9 Correct 2 ms 1252 KB Output is correct
10 Correct 2 ms 1240 KB Output is correct
11 Correct 0 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 1248 KB Output is correct
21 Correct 3 ms 1248 KB Output is correct
22 Correct 3 ms 1388 KB Output is correct
23 Correct 2 ms 1252 KB Output is correct
24 Correct 3 ms 1252 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 3 ms 1252 KB Output is correct
27 Correct 2 ms 1252 KB Output is correct
28 Correct 1 ms 996 KB Output is correct
29 Correct 3 ms 1248 KB Output is correct
30 Correct 3 ms 1536 KB Output is correct
31 Correct 2 ms 1252 KB Output is correct
32 Correct 3 ms 1248 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 4 ms 1252 KB Output is correct
8 Correct 3 ms 1252 KB Output is correct
9 Correct 3 ms 1384 KB Output is correct
10 Correct 3 ms 1376 KB Output is correct
11 Correct 3 ms 1248 KB Output is correct
12 Correct 3 ms 1248 KB Output is correct
13 Correct 3 ms 1248 KB Output is correct
# 결과 실행 시간 메모리 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 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 344 KB Output is correct
10 Correct 3 ms 1384 KB Output is correct
11 Correct 3 ms 1252 KB Output is correct
12 Correct 3 ms 1372 KB Output is correct
13 Correct 3 ms 1252 KB Output is correct
14 Correct 3 ms 1416 KB Output is correct
15 Correct 3 ms 1384 KB Output is correct
16 Correct 3 ms 1248 KB Output is correct
17 Correct 2 ms 1252 KB Output is correct
18 Correct 3 ms 1280 KB Output is correct
19 Correct 2 ms 1252 KB Output is correct
20 Correct 3 ms 1252 KB Output is correct
21 Correct 3 ms 1252 KB Output is correct
22 Correct 3 ms 1252 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 4 ms 1252 KB Output is correct
8 Correct 3 ms 1252 KB Output is correct
9 Correct 3 ms 1384 KB Output is correct
10 Correct 3 ms 1376 KB Output is correct
11 Correct 3 ms 1248 KB Output is correct
12 Correct 3 ms 1248 KB Output is correct
13 Correct 3 ms 1248 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 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 3 ms 1384 KB Output is correct
24 Correct 3 ms 1252 KB Output is correct
25 Correct 3 ms 1372 KB Output is correct
26 Correct 3 ms 1252 KB Output is correct
27 Correct 3 ms 1416 KB Output is correct
28 Correct 3 ms 1384 KB Output is correct
29 Correct 3 ms 1248 KB Output is correct
30 Correct 2 ms 1252 KB Output is correct
31 Correct 3 ms 1280 KB Output is correct
32 Correct 2 ms 1252 KB Output is correct
33 Correct 3 ms 1252 KB Output is correct
34 Correct 3 ms 1252 KB Output is correct
35 Correct 3 ms 1252 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 33 ms 10212 KB Output is correct
39 Correct 20 ms 4068 KB Output is correct
40 Correct 1 ms 996 KB Output is correct
41 Correct 37 ms 4068 KB Output is correct
42 Correct 34 ms 4068 KB Output is correct
43 Correct 25 ms 4064 KB Output is correct
44 Correct 32 ms 5600 KB Output is correct
45 Correct 1 ms 996 KB Output is correct
46 Correct 22 ms 4108 KB Output is correct
47 Incorrect 19 ms 4092 KB Output isn't correct
48 Halted 0 ms 0 KB -