QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#117334#6627. Line TownQwerty1232#0 0ms3568kbC++231.2kb2023-06-30 23:56:412024-05-31 18:44:32

Judging History

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

  • [2024-05-31 18:44:32]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3568kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-30 23:56:41]
  • 提交

answer

#include <bits/stdc++.h>

int32_t main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n;
    std::cin >> n;
    std::vector<int> input(n);
    for (int i = 0; i < n; i++) {
        std::cin >> input[i];
    }
    std::vector<int> prf(n + 1, -1), suf(n + 1, -1);
    prf[0] = 0;
    for (int i = 0; i < n; i++) {
        if (input[i] == -1) {
            prf[i + 1] = prf[i];
        } else {
            if (i >= 1 && input[i - 1] == input[i] && prf[i - 1] != -1) {
                prf[i + 1] = prf[i - 1] + 1;
            }
        }
    }
    suf.rbegin()[0] = 0;
    for (int i = 0; i < n; i++) {
        if (input.rbegin()[i] == 1) {
            suf.rbegin()[i + 1] = suf.rbegin()[i];
        } else {
            if (i >= 1 && input.rbegin()[i - 1] == input.rbegin()[i] && suf.rbegin()[i - 1] != -1) {
                suf.rbegin()[i + 1] = suf.rbegin()[i - 1] + 1;
            }
        }
    }
    int ans = -1;
    for (int i = 0; i <= n; i++) {
        if (prf[i] != -1 && suf[i] != -1) {
            if (ans == -1 || ans > prf[i] + suf[i]) {
                ans = prf[i] + suf[i];
            }
        }
    }
    std::cout << ans << "\n";

    return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 3
Accepted
time: 0ms
memory: 3464kb

input:

10
1 1 1 1 1 -1 -1 -1 1 -1

output:

-1

result:

ok 1 number(s): "-1"

Test #2:

score: -3
Wrong Answer
time: 0ms
memory: 3504kb

input:

10
1 1 1 1 1 1 -1 1 1 -1

output:

4

result:

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

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Wrong Answer

Test #60:

score: 4
Accepted
time: 0ms
memory: 3568kb

input:

10
3 10 5 -9 7 2 -6 1 8 0

output:

-1

result:

ok 1 number(s): "-1"

Test #61:

score: -4
Wrong Answer
time: 0ms
memory: 3568kb

input:

10
-9 0 -1 7 5 10 6 3 2 -8

output:

-1

result:

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

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #3:

0%

Subtask #8:

score: 0
Skipped

Dependency #1:

0%