QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#664691#4428. FenceXiao_NanniangWA 267ms7036kbC++231.8kb2024-10-21 21:46:492024-10-21 21:46:49

Judging History

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

  • [2024-10-21 21:46:49]
  • 评测
  • 测评结果:WA
  • 用时:267ms
  • 内存:7036kb
  • [2024-10-21 21:46:49]
  • 提交

answer

#include <iostream>
#include <vector>
#include <array>

using namespace std;

struct Node {
    int mode = -1;
    array<int, 2> cnt = {};
    void Output(pair<int, bool>& cur, int b) const {
        if (mode == -1) {
            int duan = (cnt[0] + b - 1) / b;
            int t = (duan >> 1) * b;
            cur.second ^= duan & 1;
            if (cur.second) {
                t = cnt[0] - t;
            }
            cur.first += t;
            return;
        }
        cur.first += cnt[cur.second];
        cur.second ^= mode;
    }
    // only called when both mode is not -1
    void Concatenate(const Node& other) {
        cnt[0] += other.cnt[mode];
        cnt[1] += other.cnt[mode ^ 1];
        mode ^= other.mode;
    }
};

int n;
vector<Node> a;
int m;

void Solve() {
    cin >> n;
    m = 0;
    a.resize(n);
    for (auto& x : a) {
        cin >> x.cnt[0];
        m = max(m, x.cnt[0]);
    }
    for (int i = 1; i <= m; i++) {
        for (auto& x : a) {
            if (x.mode == -1 && x.cnt[0] == i) {
                x.mode = 1;
            }
        }
        vector<Node> newA;
        for (const auto x : a) {
            if (newA.size() && x.mode != -1 && newA.back().mode != -1) {
                newA.back().Concatenate(x);
                continue;
            }
            newA.push_back(x);
        }
        swap(a, newA);
        pair<int, bool> cur = {};
        for (const auto x : a) {
            // cout << x.cnt[0] << ',' << x.mode << endl;
            x.Output(cur, i);
        }
        cout << cur.first << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while (T--) {
        Solve();
    }
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 267ms
memory: 7036kb

input:

5
333834
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

500000
500000
499995
499987
500000
500032
499996
499987
500032
500000
499994
499998
499981
499996
500080
500090
500077
500032
499980
499915
500035
499941
500055
499923
500000
499980
499935
500042
500174
499905
500002
499998
500218
499899
499965
500010
500144
500242
499839
499915
499987
500010
500122...

result:

wrong answer 500001st lines differ - expected: '500000', found: '500001'