Submission #793714

# Submission time Handle Problem Language Result Execution time Memory
793714 2023-07-26T05:49:44 Z GEN 이지후(#10094) Flip it and Stick it (CCO23_day2problem1) C++17
18 / 25
1000 ms 1620 KB
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = array<lint, 2>;
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s, t;
	cin >> s >> t;
	if (sz(t) == 1) {
		if (count(all(s), t[0]) == 0)
			cout << "0\n";
		else
			cout << "-1\n";
		return 0;
	}
	if (sz(t) == 2) {
		if (t[0] != t[1]) {
			if (t[0] == '0') {
				for (auto &x : s)
					x ^= 1;
			}
			t = "10";
			vector<int> poses;
			for (int i = 0; i < sz(s); i++) {
				if (s[i] == '1')
					poses.push_back(i);
			}
			poses.push_back(sz(s));
			int ans = 0;
			for (int i = 1; i < sz(poses); i++)
				if (poses[i - 1] + 1 != poses[i])
					ans++;
			cout << ans << "\n";
		} else {
			int cnt = count(all(s), t[0]);
			if (2 * cnt - 1 <= sz(s)) {
				int ans = 0;
				for (int i = 0; i + 1 < sz(s); i++) {
					if (s[i] == t[0] && s[i + 1] == t[0])
						ans++;
				}
				cout << ans << "\n";
			} else {
				cout << "-1\n";
			}
		}
		return 0;
	}
	if (t[0] == '1') {
		for (auto &x : s)
			x ^= 1;
		for (auto &x : t)
			x ^= 1;
	}
	if (t[2] == '1') {
		int ans = 0;
		for (int i = 0; i + 3 <= sz(s); i++) {
			if (s.substr(i, 3) == t)
				ans++;
		}
		cout << ans << "\n";
		return 0;
	} else if (t[1] == '1') {
		int ans = 0;
		for (int i = 0; i + 3 <= sz(s); i++) {
			if (s.substr(i, 3) == t) {
				ans++;
			}
		}
		cout << (ans + 1) / 2 << "\n";
		return 0;
	}
	int cnt = count(all(s), '1');
	if (3 * cnt + 2 >= sz(s)) {
		int ans = 0;
		for (int i = 0; i < sz(s);) {
			if (s[i] == '1') {
				i++;
				continue;
			}
			int j = i;
			int cnt = 0;
			while(j < sz(s) && s[i] == s[j]) j++;
			ans += (j - i - 1) / 2;
		}
		cout << ans << "\n";
	} else {
		cout << "-1\n";
	}
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:87:8: warning: unused variable 'cnt' [-Wunused-variable]
   87 |    int cnt = 0;
      |        ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 2 ms 1620 KB Output is correct
7 Correct 2 ms 1620 KB Output is correct
8 Correct 2 ms 1112 KB Output is correct
9 Correct 2 ms 1112 KB Output is correct
10 Correct 2 ms 1112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 2 ms 1620 KB Output is correct
7 Correct 2 ms 1620 KB Output is correct
8 Correct 2 ms 1112 KB Output is correct
9 Correct 2 ms 1112 KB Output is correct
10 Correct 2 ms 1112 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 2 ms 1620 KB Output is correct
21 Correct 2 ms 1620 KB Output is correct
22 Correct 1 ms 1112 KB Output is correct
23 Correct 2 ms 1112 KB Output is correct
24 Correct 2 ms 1112 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 5 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 4 ms 604 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 3 ms 604 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
19 Correct 3 ms 604 KB Output is correct
20 Correct 3 ms 604 KB Output is correct
21 Correct 3 ms 604 KB Output is correct
22 Correct 3 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 5 ms 604 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 3 ms 604 KB Output is correct
24 Correct 3 ms 604 KB Output is correct
25 Correct 3 ms 604 KB Output is correct
26 Correct 4 ms 604 KB Output is correct
27 Correct 3 ms 604 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
29 Correct 3 ms 604 KB Output is correct
30 Correct 3 ms 604 KB Output is correct
31 Correct 3 ms 604 KB Output is correct
32 Correct 3 ms 604 KB Output is correct
33 Correct 3 ms 604 KB Output is correct
34 Correct 3 ms 604 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Execution timed out 1074 ms 212 KB Time limit exceeded
38 Halted 0 ms 0 KB -