QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#196558#6352. SPPPSPSS.jrjyyWA 0ms3564kbC++202.4kb2023-10-01 19:06:192023-10-01 19:06:19

Judging History

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

  • [2023-10-01 19:06:19]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3564kb
  • [2023-10-01 19:06:19]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);

    int n;
    std::cin >> n;

    std::vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i];
        --a[i];
    }

    if (std::is_sorted(a.begin(), a.end())) {
        std::cout << "0\n\n";
        return 0;
    }

    std::string ans(n, 'P');
    auto work = [&]() {
        int m = n / 2;
        i64 sum = std::accumulate(a.begin(), a.begin() + m, 0ll);
        if (sum == 1ll * m * (m - 1) / 2) {
            int l = m - 1, r = m - 1;
            while (l >= 0 && a[l] == l) {
                --l;
            }
            while (r < n && a[r] == r) {
                ++r;
            }
            int x = l + 1, y = n - r, z = std::max(x, y) + (x == y);
            std::string res;
            if (x >= y) {
                res = std::string(z - 1, 'S') + "P";
            } else {
                res = std::string(z - 1, 'P') + "S";
            }
            if (res.size() < ans.size()) {
                ans = res;
            }
        }

        std::string res;
        res = std::string(m, 'P') + "S";
        std::priority_queue<int> p;
        std::priority_queue<int, std::vector<int>, std::greater<>> q;
        for (int i = 0; i < m; ++i) {
            p.push(a[i]);
        }
        for (int i = m; i < n; ++i) {
            q.push(a[i]);
        }
        if (n % 2 == 0) {
            q.push(p.top());
            p.pop();
        }
        for (int i = 0; !p.empty() && p.top() >= int(p.size()); ++i) {
            if (i % 2 == 0) {
                res += "P";
                while (p.size() < res.size()) {
                    p.push(q.top());
                    q.pop();
                }
            } else {
                res += "S";
                while (q.size() < res.size()) {
                    q.push(p.top());
                    p.pop();
                }
            }
        }
        if (res.size() < ans.size()) {
            ans = res;
        }
    };

    std::reverse(a.begin(), a.end());
    for (auto &x : a) {
        x = n - x - 1;
    }
    work();
    for (auto &x : ans) {
        x = "PS"[x == 'P'];
    }
    std::reverse(a.begin(), a.end());
    for (auto &x : a) {
        x = n - x - 1;
    }
    work();

    std::cout << ans << ".\n";

    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3564kb

input:

3
1 2 3

output:

0


result:

wrong answer Token "0" doesn't correspond to pattern "[PS]{0,1000001}."