QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#132984 | #6628. Flip it and Stick it | Cyanmond# | 6 | 6ms | 5488kb | C++14 | 2.3kb | 2023-08-01 12:38:18 | 2024-07-04 01:04:10 |
Judging History
answer
#include <bits/stdc++.h>
// #include "atcoder/modint"
using i64 = long long;
// using Fp = atcoder::modint998244353;
int main() {
std::string S, T;
std::cin >> S >> T;
const int N = (int)S.size();
if (T.size() == 1) {
const auto s = std::count(S.begin(), S.end(), T[0]);
if (s) std::cout << -1 << std::endl;
else std::cout << 0 << std::endl;
return 0;
}
std::vector<std::pair<char, int>> P;
{
int last = 0;
for (int i = 0; i < N; ++i) {
if (S[i] != S[last]) {
P.push_back({S[last], i - last});
last = i;
}
}
P.push_back({S[last], N - last});
}
const int U = (int)P.size();
if (T.size() == 2 and T[0] != T[1]) {
i64 ans = 0;
for (int i = 0; i < U; ++i) {
if (i != 0 and P[i].first == T[1]) ++ans;
}
std::cout << ans << std::endl;
} else if (T.size() == 2) {
int cnta = 0, cntb = 0;
for (const auto e : S) {
if (e == T[0]) ++cnta;
else ++cntb;
}
if (cntb + 1 < cnta) {
std::cout << -1 << std::endl;
} else {
int ans = 0;
for (int i = 0; i < N - 1; ++i) {
if (S[i] == S[i + 1] and S[i] == T[0]) ++ans;
}
std::cout << ans << std::endl;
}
return 0;
}
assert(T.size() == 3);
if (T[0] != T[2]) {
if (T[1] == T[2]) {
std::reverse(T.begin(), T.end());
std::reverse(S.begin(), S.end());
std::reverse(P.begin(), P.end());
}
if (T[0] == '1') {
for (auto &e : S) {
if (e == '0') e = '1';
else e = '0';
}
for (auto &e : T) {
if (e == '0') e = '1';
else e = '0';
}
for (auto &[e, len] : P) {
if (e == '0') e = '1';
else e = '0';
}
}
int ans = 0;
for (int i = 0; i < N - 2; ++i) {
if (S.substr(i, 3) == T) {
++ans;
}
}
std::cout << ans << std::endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 1
Accepted
Test #1:
score: 1
Accepted
time: 0ms
memory: 3584kb
input:
1 0
output:
0
result:
ok 1 number(s): "0"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
1 1
output:
-1
result:
ok 1 number(s): "-1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3944kb
input:
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: 0
Accepted
time: 3ms
memory: 3716kb
input:
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 3ms
memory: 3652kb
input:
101001000011101010101001001010010110111111001100110001111101111110110110101011111010001101111001101101010111101100000110001110001100000101111100000110111110001010101101101110001000011010000101000110110010110110100001110001111001010000000010000000101000000100110011101110100111111101111111111110010101...
output:
-1
result:
ok 1 number(s): "-1"
Test #6:
score: 0
Accepted
time: 3ms
memory: 3720kb
input:
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 3ms
memory: 3752kb
input:
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
-1
result:
ok 1 number(s): "-1"
Subtask #2:
score: 0
Runtime Error
Test #8:
score: 0
Runtime Error
input:
0 01
output:
0
result:
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 5
Accepted
Test #40:
score: 5
Accepted
time: 0ms
memory: 3564kb
input:
11 011
output:
0
result:
ok 1 number(s): "0"
Test #41:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
0 110
output:
0
result:
ok 1 number(s): "0"
Test #42:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
01 100
output:
0
result:
ok 1 number(s): "0"
Test #43:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
110 110
output:
1
result:
ok 1 number(s): "1"
Test #44:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
010 001
output:
0
result:
ok 1 number(s): "0"
Test #45:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
001001001001 001
output:
4
result:
ok 1 number(s): "4"
Test #46:
score: 0
Accepted
time: 4ms
memory: 3644kb
input:
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
0
result:
ok 1 number(s): "0"
Test #47:
score: 0
Accepted
time: 4ms
memory: 3716kb
input:
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
0
result:
ok 1 number(s): "0"
Test #48:
score: 0
Accepted
time: 0ms
memory: 4364kb
input:
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
24856
result:
ok 1 number(s): "24856"
Test #49:
score: 0
Accepted
time: 6ms
memory: 4432kb
input:
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
0
result:
ok 1 number(s): "0"
Test #50:
score: 0
Accepted
time: 5ms
memory: 4432kb
input:
010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010...
output:
62521
result:
ok 1 number(s): "62521"
Test #51:
score: 0
Accepted
time: 6ms
memory: 5488kb
input:
011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011...
output:
66666
result:
ok 1 number(s): "66666"
Test #52:
score: 0
Accepted
time: 6ms
memory: 5476kb
input:
110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110...
output:
66666
result:
ok 1 number(s): "66666"
Subtask #5:
score: 0
Wrong Answer
Test #53:
score: 5
Accepted
time: 0ms
memory: 3472kb
input:
11 011
output:
0
result:
ok 1 number(s): "0"
Test #54:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
01 100
output:
0
result:
ok 1 number(s): "0"
Test #55:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
011 011
output:
1
result:
ok 1 number(s): "1"
Test #56:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
010 100
output:
0
result:
ok 1 number(s): "0"
Test #57:
score: -5
Wrong Answer
time: 0ms
memory: 3780kb
input:
0 010
output:
result:
wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements
Subtask #6:
score: 0
Skipped
Dependency #4:
100%
Accepted
Dependency #5:
0%