QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#297325#6628. Flip it and Stick itMysterious_Cat9 2ms4592kbC++142.6kb2024-01-04 10:54:362024-01-04 10:54:36

Judging History

你现在查看的是最新测评结果

  • [2024-01-04 10:54:36]
  • 评测
  • 测评结果:9
  • 用时:2ms
  • 内存:4592kb
  • [2024-01-04 10:54:36]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 2e5;

string s, t;

int main() {
    // freopen("a.in", "r", stdin);
    // freopen("a.out", "w", stdout);
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> s >> t;
    if (t == "0" || t == "1") {
        for (char c : s) {
            if (c == t[0]) {
                cout << "-1\n";
                return 0;
            }
        }
        cout << "0\n";
    }
    if (t == "00" || t == "11") {
        int k = t[0] - '0', ans = 0, cnt = 0, c[2] = {};
        for (int i = 0; i < s.size(); i++) {
            if (i && s[i] != s[i - 1]) {
                c[s[i - 1] - '0'] += cnt;
                if (s[i - 1] == t[0]) {
                    ans += cnt - 1;
                }
                cnt = 0;
            }
            cnt++;
        }
        c[s.back() - '0'] += cnt;
        if (s.back() == t[0]) {
            ans += cnt - 1;
        }
        if (c[0] <= c[1] + 1) {
            cout << ans << '\n';
        }
        else {
            cout << "-1\n";
        }
    }
    if (t == "01" || t == "10") {
        int ans = 0;
        for (int i = 1; i < s.size(); i++) {
            if (s[i - 1] == t[0] && s[i] == t[1]) {
                ans++;
            }
        }
        cout << ans << '\n';
    }
    if (t == "000" || t == "111") {
        int k = t[0] - '0', n = 0, cnt = 0, c[2] = {0}, a[N] = {0};
        for (int i = 0; i < s.size(); i++) {
            cnt++;
            if (i == s.size() - 1 || s[i] != s[i + 1]) {
                c[s[i] - '0'] += cnt;
                if (s[i] == t[0]) {
                    a[++n] = cnt;
                }
                cnt = 0;
            }
        }
        if ((c[k] - 1) / 2 > c[k ^ 1]) {
            cout << "-1\n";
        }
        else {
            int ans1 = 0, ans2 = 0;
            for (int i = 1; i <= n; i++) {
                if (a[i] == 1) {
                    continue;
                }
                if (a[i] & 1) {
                    ans2++;
                }
                ans1 += a[i] / 2 - 1;
            }
            while (c[k ^ 1] - n + 1 < ans1) {
                ans2++;
                n--;
            }
            cout << ans1 + ans2 << '\n';
        }
    }
    if (t == "010" || t == "101" || t == "001" || t == "011" || t == "100" || t == "110") {
        int ans = 0;
        for (int i = 2; i < s.size(); i++) {
            if (s[i - 2] == t[0] && s[i - 1] == t[1] && s[i] == t[2]) {
                ans++;
            }
        }
        cout << ans << '\n';
    }

    return 0;
}

詳細信息

Subtask #1:

score: 1
Accepted

Test #1:

score: 1
Accepted
time: 1ms
memory: 4408kb

input:

1
0

output:

0

result:

ok 1 number(s): "0"

Test #2:

score: 0
Accepted
time: 1ms
memory: 4336kb

input:

1
1

output:

-1

result:

ok 1 number(s): "-1"

Test #3:

score: 0
Accepted
time: 1ms
memory: 4592kb

input:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: 0
Accepted
time: 1ms
memory: 4440kb

input:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

0

result:

ok 1 number(s): "0"

Test #5:

score: 0
Accepted
time: 1ms
memory: 4488kb

input:

101001000011101010101001001010010110111111001100110001111101111110110110101011111010001101111001101101010111101100000110001110001100000101111100000110111110001010101101101110001000011010000101000110110010110110100001110001111001010000000010000000101000000100110011101110100111111101111111111110010101...

output:

-1

result:

ok 1 number(s): "-1"

Test #6:

score: 0
Accepted
time: 1ms
memory: 4492kb

input:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0

result:

ok 1 number(s): "0"

Test #7:

score: 0
Accepted
time: 1ms
memory: 4488kb

input:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

-1

result:

ok 1 number(s): "-1"

Subtask #2:

score: 3
Accepted

Test #8:

score: 3
Accepted
time: 1ms
memory: 4392kb

input:

0
01

output:

0

result:

ok 1 number(s): "0"

Test #9:

score: 0
Accepted
time: 1ms
memory: 4332kb

input:

0
10

output:

0

result:

ok 1 number(s): "0"

Test #10:

score: 0
Accepted
time: 1ms
memory: 4288kb

input:

01
01

output:

1

result:

ok 1 number(s): "1"

Test #11:

score: 0
Accepted
time: 0ms
memory: 4408kb

input:

01
10

output:

0

result:

ok 1 number(s): "0"

Test #12:

score: 0
Accepted
time: 1ms
memory: 4408kb

input:

1010101010
10

output:

5

result:

ok 1 number(s): "5"

Test #13:

score: 0
Accepted
time: 1ms
memory: 4588kb

input:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0

result:

ok 1 number(s): "0"

Test #14:

score: 0
Accepted
time: 0ms
memory: 4540kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0

result:

ok 1 number(s): "0"

Test #15:

score: 0
Accepted
time: 0ms
memory: 4456kb

input:

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101...

output:

100000

result:

ok 1 number(s): "100000"

Test #16:

score: 0
Accepted
time: 0ms
memory: 4592kb

input:

000110111001011000010001010010010000010100100000011101010000001000110011100000011011100101110110000001000000000011001010001101001110011111001101110010001100000000010000000100100011000111010011100110011101100011000100011001010000010001001010010101100000100000010010110000000001011100100001000010100100...

output:

43860

result:

ok 1 number(s): "43860"

Test #17:

score: 0
Accepted
time: 1ms
memory: 4488kb

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: 1ms
memory: 4292kb

input:

0
01

output:

0

result:

ok 1 number(s): "0"

Test #19:

score: 0
Accepted
time: 1ms
memory: 4396kb

input:

0
10

output:

0

result:

ok 1 number(s): "0"

Test #20:

score: 0
Accepted
time: 0ms
memory: 4340kb

input:

01
01

output:

1

result:

ok 1 number(s): "1"

Test #21:

score: 0
Accepted
time: 1ms
memory: 4408kb

input:

01
10

output:

0

result:

ok 1 number(s): "0"

Test #22:

score: 0
Accepted
time: 0ms
memory: 4336kb

input:

1
00

output:

0

result:

ok 1 number(s): "0"

Test #23:

score: 0
Accepted
time: 1ms
memory: 4324kb

input:

1
11

output:

0

result:

ok 1 number(s): "0"

Test #24:

score: 0
Accepted
time: 1ms
memory: 4456kb

input:

10
00

output:

0

result:

ok 1 number(s): "0"

Test #25:

score: -4
Wrong Answer
time: 1ms
memory: 4456kb

input:

11
11

output:

1

result:

wrong answer 1st numbers differ - expected: '-1', found: '1'

Subtask #4:

score: 5
Accepted

Test #40:

score: 5
Accepted
time: 1ms
memory: 4284kb

input:

11
011

output:

0

result:

ok 1 number(s): "0"

Test #41:

score: 0
Accepted
time: 1ms
memory: 4392kb

input:

0
110

output:

0

result:

ok 1 number(s): "0"

Test #42:

score: 0
Accepted
time: 1ms
memory: 4404kb

input:

01
100

output:

0

result:

ok 1 number(s): "0"

Test #43:

score: 0
Accepted
time: 1ms
memory: 4336kb

input:

110
110

output:

1

result:

ok 1 number(s): "1"

Test #44:

score: 0
Accepted
time: 1ms
memory: 4396kb

input:

010
001

output:

0

result:

ok 1 number(s): "0"

Test #45:

score: 0
Accepted
time: 1ms
memory: 4392kb

input:

001001001001
001

output:

4

result:

ok 1 number(s): "4"

Test #46:

score: 0
Accepted
time: 1ms
memory: 4468kb

input:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0

result:

ok 1 number(s): "0"

Test #47:

score: 0
Accepted
time: 1ms
memory: 4416kb

input:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

0

result:

ok 1 number(s): "0"

Test #48:

score: 0
Accepted
time: 2ms
memory: 4592kb

input:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

24856

result:

ok 1 number(s): "24856"

Test #49:

score: 0
Accepted
time: 1ms
memory: 4528kb

input:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

0

result:

ok 1 number(s): "0"

Test #50:

score: 0
Accepted
time: 1ms
memory: 4424kb

input:

010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010...

output:

62521

result:

ok 1 number(s): "62521"

Test #51:

score: 0
Accepted
time: 0ms
memory: 4532kb

input:

011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011...

output:

66666

result:

ok 1 number(s): "66666"

Test #52:

score: 0
Accepted
time: 0ms
memory: 4536kb

input:

110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110...

output:

66666

result:

ok 1 number(s): "66666"

Subtask #5:

score: 0
Wrong Answer

Test #53:

score: 5
Accepted
time: 1ms
memory: 4464kb

input:

11
011

output:

0

result:

ok 1 number(s): "0"

Test #54:

score: 0
Accepted
time: 0ms
memory: 4336kb

input:

01
100

output:

0

result:

ok 1 number(s): "0"

Test #55:

score: 0
Accepted
time: 1ms
memory: 4460kb

input:

011
011

output:

1

result:

ok 1 number(s): "1"

Test #56:

score: 0
Accepted
time: 1ms
memory: 4288kb

input:

010
100

output:

0

result:

ok 1 number(s): "0"

Test #57:

score: 0
Accepted
time: 1ms
memory: 4408kb

input:

0
010

output:

0

result:

ok 1 number(s): "0"

Test #58:

score: 0
Accepted
time: 1ms
memory: 4460kb

input:

10
101

output:

0

result:

ok 1 number(s): "0"

Test #59:

score: 0
Accepted
time: 1ms
memory: 4368kb

input:

010
010

output:

1

result:

ok 1 number(s): "1"

Test #60:

score: 0
Accepted
time: 0ms
memory: 4364kb

input:

000
101

output:

0

result:

ok 1 number(s): "0"

Test #61:

score: 0
Accepted
time: 1ms
memory: 4284kb

input:

001001001001
100

output:

3

result:

ok 1 number(s): "3"

Test #62:

score: 0
Accepted
time: 0ms
memory: 4424kb

input:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0

result:

ok 1 number(s): "0"

Test #63:

score: 0
Accepted
time: 0ms
memory: 4424kb

input:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

0

result:

ok 1 number(s): "0"

Test #64:

score: 0
Accepted
time: 2ms
memory: 4492kb

input:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

25010

result:

ok 1 number(s): "25010"

Test #65:

score: 0
Accepted
time: 1ms
memory: 4536kb

input:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

0

result:

ok 1 number(s): "0"

Test #66:

score: 0
Accepted
time: 1ms
memory: 4540kb

input:

110001101111100110100110010110111101001001110110101110011010011000101000011001110011100111110111100001111111101011001001010111001100001001000001010000100010001001010101000101100011110110001100101110101101001100011101110111011110000111111110110110001001001100110110111001010001111111101100111011111011...

output:

62502

result:

ok 1 number(s): "62502"

Test #67:

score: 0
Accepted
time: 1ms
memory: 4588kb

input:

011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011...

output:

66666

result:

ok 1 number(s): "66666"

Test #68:

score: 0
Accepted
time: 0ms
memory: 4456kb

input:

110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110...

output:

66666

result:

ok 1 number(s): "66666"

Test #69:

score: -5
Wrong Answer
time: 0ms
memory: 4452kb

input:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

22345

result:

wrong answer 1st numbers differ - expected: '11173', found: '22345'

Subtask #6:

score: 0
Skipped

Dependency #4:

100%
Accepted

Dependency #5:

0%