QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#297287 | #6628. Flip it and Stick it | chy12321 | 4 | 1ms | 3812kb | C++14 | 2.1kb | 2024-01-04 09:27:25 | 2024-01-04 09:27:26 |
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 2e5 + 10;
int n, m, ans;
string s, t;
inline void change() {for (char &i : s) i = '0' + '1' - i;}
int main() {
ios_base::sync_with_stdio(0); cin.tie(nullptr), cout.tie(nullptr);
cin >> s >> t; n = s.length(), m = t.length();
if (m == 1) ans = s.find(t) == s.npos ? 0 : -1;
else if (m == 2) {
if (t == "00") {
if (count(s.begin(), s.end(), '0') > (n + 1) / 2) ans = -1;
else for (int i = 1; i < n; i++) ans += (s[i] == s[i - 1] && s[i] == '0');
}
if (t == "10") change();
for (int i = 1; i < n; i++) ans += (s[i] != s[i - 1] && s[i] == '1');
} else if (m == 3) {
if (t == "010" || t == "101") {
if (t == "101") change();
for (int i = 1; i < n - 1; i++) ans += (s[i - 1] != s[i] && s[i] != s[i + 1] && s[i] == '1');
} else if (t == "000" || t == "111") {
if (t == "111") change();
if (count(s.begin(), s.end(), '1') * 3 + 2 < n) ans = 0;
else {
int c2 = 0;
for (int i = 1; i < n; i++) c2 += (s[i] == '1' && s[i - 1] == '1');
c2 += (s[0] == '1') + (s[n - 1] == '1'), s[n] = '1';
for (int i = 0, cnt = 0; i <= n; i++) {
if (s[i] == '0') cnt++;
else {
if (cnt <= 2) {cnt = 0; continue;}
else {
ans += (cnt - 1) / 2;
int tmp = min(c2, cnt / 2 - 1);
c2 -= tmp, ans += max(0, cnt / 2 - 1 - tmp), cnt = 0;
}
}
}
}
} else {
if (count(t.begin(), t.end(), '0') == 1) change();
if (t[0] == '1') reverse(s.begin(), s.end());
for (int i = 0, cnt = 0; i < n; i++) {
if (s[i] == '0') cnt++;
else ans += (cnt >= 2), cnt = 0;
}
}
}
cout << ans;
return 0;
}
詳細信息
Subtask #1:
score: 1
Accepted
Test #1:
score: 1
Accepted
time: 0ms
memory: 3528kb
input:
1 0
output:
0
result:
ok 1 number(s): "0"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
1 1
output:
-1
result:
ok 1 number(s): "-1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3680kb
input:
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3680kb
input:
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3808kb
input:
101001000011101010101001001010010110111111001100110001111101111110110110101011111010001101111001101101010111101100000110001110001100000101111100000110111110001010101101101110001000011010000101000110110010110110100001110001111001010000000010000000101000000100110011101110100111111101111111111110010101...
output:
-1
result:
ok 1 number(s): "-1"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3756kb
input:
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3804kb
input:
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
-1
result:
ok 1 number(s): "-1"
Subtask #2:
score: 3
Accepted
Test #8:
score: 3
Accepted
time: 0ms
memory: 3552kb
input:
0 01
output:
0
result:
ok 1 number(s): "0"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
0 10
output:
0
result:
ok 1 number(s): "0"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
01 01
output:
1
result:
ok 1 number(s): "1"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
01 10
output:
0
result:
ok 1 number(s): "0"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
1010101010 10
output:
5
result:
ok 1 number(s): "5"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3684kb
input:
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
0
result:
ok 1 number(s): "0"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
0
result:
ok 1 number(s): "0"
Test #15:
score: 0
Accepted
time: 1ms
memory: 3764kb
input:
010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101...
output:
100000
result:
ok 1 number(s): "100000"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
000110111001011000010001010010010000010100100000011101010000001000110011100000011011100101110110000001000000000011001010001101001110011111001101110010001100000000010000000100100011000111010011100110011101100011000100011001010000010001001010010101100000100000010010110000000001011100100001000010100100...
output:
43860
result:
ok 1 number(s): "43860"
Test #17:
score: 0
Accepted
time: 1ms
memory: 3760kb
input:
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
44072
result:
ok 1 number(s): "44072"
Subtask #3:
score: 0
Wrong Answer
Dependency #2:
100%
Accepted
Test #18:
score: 4
Accepted
time: 0ms
memory: 3588kb
input:
0 01
output:
0
result:
ok 1 number(s): "0"
Test #19:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
0 10
output:
0
result:
ok 1 number(s): "0"
Test #20:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
01 01
output:
1
result:
ok 1 number(s): "1"
Test #21:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
01 10
output:
0
result:
ok 1 number(s): "0"
Test #22:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
1 00
output:
0
result:
ok 1 number(s): "0"
Test #23:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
1 11
output:
0
result:
ok 1 number(s): "0"
Test #24:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
10 00
output:
0
result:
ok 1 number(s): "0"
Test #25:
score: -4
Wrong Answer
time: 0ms
memory: 3576kb
input:
11 11
output:
0
result:
wrong answer 1st numbers differ - expected: '-1', found: '0'
Subtask #4:
score: 0
Wrong Answer
Test #40:
score: 5
Accepted
time: 0ms
memory: 3576kb
input:
11 011
output:
0
result:
ok 1 number(s): "0"
Test #41:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
0 110
output:
0
result:
ok 1 number(s): "0"
Test #42:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
01 100
output:
0
result:
ok 1 number(s): "0"
Test #43:
score: -5
Wrong Answer
time: 0ms
memory: 3504kb
input:
110 110
output:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'
Subtask #5:
score: 0
Wrong Answer
Test #53:
score: 5
Accepted
time: 0ms
memory: 3556kb
input:
11 011
output:
0
result:
ok 1 number(s): "0"
Test #54:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
01 100
output:
0
result:
ok 1 number(s): "0"
Test #55:
score: -5
Wrong Answer
time: 0ms
memory: 3556kb
input:
011 011
output:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'
Subtask #6:
score: 0
Skipped
Dependency #4:
0%