QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#138207#6627. Line TownCyanmond#0 0ms3684kbC++171.9kb2023-08-11 09:17:402024-05-23 13:10:34

Judging History

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

  • [2024-05-23 13:10:34]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3684kb
  • [2023-08-11 09:17:40]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

#define rep(i, l, r) for (int i = (l); i < (r); ++i)
#define per(i, l, r) for (int i = (r - 1); i >= (l); --i)
#define ALL(x) (x).begin(), (x).end()

int main() {
    int N;
    cin >> N;
    vector<int> H(N);
    for (auto &e : H)
        cin >> e;

    if (all_of(ALL(H), [](int v) { return abs(v) == 1; })) {
        vector<pair<int, int>> cp;
        int last = 0;
        rep (i, 0, N) {
            if (H[i] != H[last]) {
                cp.push_back({H[last], i - last});
                last = i;
            }
        }
        cp.push_back({H[last], N - last});
        int l = -1, r = (int)cp.size();
        rep (i, 0, (int)cp.size()) {
            if (cp[i].second % 2 == 1 and cp[i].first == -1)
                l = max(l, i);
            if (cp[i].second % 2 == 1 and cp[i].first == 1)
                r = min(r, i);
        }
        int cnt0l = 0, cnt0r = 0, cnt1l = 0, cnt1r = 0;
        rep (i, 0, l + 1) {
            if (cp[i].first == 1)
                cnt0l += cp[i].second;
            else
                cnt1l += cp[i].second;
        }
        rep (i, l + 1, (int)cp.size()) {
            if (cp[i].first == 1)
                cnt0r += cp[i].second;
            else
                cnt1r += cp[i].second;
        }
        int ans = 1 << 30;
        rep (i, l, r) {
            ans = min(ans, (cnt0l + cnt1r) / 2);
            if (i != r - 1) {
                if (cp[i + 1].first == 1) {
                    cnt0l += cp[i + 1].second;
                    cnt1l -= cp[i + 1].second;
                } else {
                    cnt0r += cp[i + 1].second;
                    cnt1r -= cp[i + 1].second;
                }
            }
        }
        if (ans == (1 << 30))
            ans = -1;
        cout << ans << endl;
    }
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

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: 3572kb

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: 0
Wrong Answer
time: 0ms
memory: 3684kb

input:

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

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #3:

0%

Subtask #8:

score: 0
Skipped

Dependency #1:

0%