Submission #793599

# Submission time Handle Problem Language Result Execution time Memory
793599 2023-07-26T04:30:51 Z 박상훈(#10058) Flip it and Stick it (CCO23_day2problem1) C++17
13 / 25
3 ms 680 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
char s[1001000], t[10], b[1001000];
int n, m;

int f(char *s){
	for (int i=1;i<=m;i++) if (s[i-1] != t[i]) return 0;
	return 1;
}

int solve(char x, char y){
	int ret = 0;

	for (int i=1;i<=n;i++){
		b[i] = x;
		if (i>=m && f(b + i-m+1)==1){
			b[i] = y;
		}

		ret += (b[i]=='1');
	}

	return ret;
}

int main(){
	scanf("%s", s+1);
	scanf("%s", t+1);

	n = strlen(s+1);
	m = strlen(t+1);

	int mn = solve('0', '1'), mx = solve('1', '0');
	int cnt = 0, cnt1 = 0;

	for (int i=1;i<=n-m+1;i++){
		cnt += f(s+i);
	} 

	for (int i=1;i<=n;i++) cnt1 += (s[i]=='1');

	if (mn <= cnt1 && cnt1 <= mx) printf("%d\n", cnt);
	else printf("-1\n");
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |  scanf("%s", s+1);
      |  ~~~~~^~~~~~~~~~~
Main.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |  scanf("%s", t+1);
      |  ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 668 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 3 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 668 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 3 ms 596 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 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 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 2 ms 596 KB Output is correct
23 Correct 2 ms 596 KB Output is correct
24 Correct 2 ms 596 KB Output is correct
25 Correct 0 ms 300 KB Output is correct
26 Correct 2 ms 596 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 3 ms 596 KB Output is correct
29 Correct 2 ms 596 KB Output is correct
30 Correct 2 ms 596 KB Output is correct
31 Correct 2 ms 596 KB Output is correct
32 Correct 2 ms 596 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 2 ms 596 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 596 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 680 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Incorrect 2 ms 596 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 2 ms 596 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 596 KB Output is correct
24 Correct 2 ms 596 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 2 ms 596 KB Output is correct
27 Correct 2 ms 680 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 2 ms 596 KB Output is correct
30 Incorrect 2 ms 596 KB Output isn't correct
31 Halted 0 ms 0 KB -