QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#749616#5500. Barsagh4WA 350ms4008kbC++231.7kb2024-11-15 07:13:322024-11-15 07:13:33

Judging History

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

  • [2024-11-15 07:13:33]
  • 评测
  • 测评结果:WA
  • 用时:350ms
  • 内存:4008kb
  • [2024-11-15 07:13:32]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int z;
    cin >> z;

    while(z--) {
        int n;
        cin >> n;
        unordered_set<int> bars;
        vector<int> taxes(n);

        for(int i = 0; i < n; ++i) {
            cin >> taxes[i];
        }

        stack<pair<int, int>> s;
        s.push({0, n-1});
        bars.insert(0);
        bars.insert(n-1);
        while(!s.empty()) {
            auto [l, r] = s.top();
            s.pop();

            int ij = r - l;
            int suma_1 = ij * taxes[l] + ij * taxes[r];

            int mm = -1;
            int max_sum = 0;

            for(int m = l + 1; m < r; ++m) {
                int i = m - l;
                int j = r - m;
                int suma_2 = taxes[l]*i + taxes[r]*j + taxes[m]*(i+j);
                if(suma_2 > suma_1) {
                    if(suma_2 > max_sum) {
                        mm = m;
                        max_sum = suma_2;
                    }
                }
            }
            if(mm != -1) {
                bars.insert(mm);
                s.push({l, mm});
                s.push({mm, r});
            }
        }

        long long ans = 0;

        int L = taxes[0];

        for(int i = 1; i < n; ++i) {
            ans += L;
            if(bars.count(i) != 0) {
                L = taxes[i];
            }
        }

        int R = taxes[n-1];

        for(int i = n-2; i >= 0; --i) {
            ans += R;
            if(bars.count(i) != 0) {
                R = taxes[i];
            }
        }

        cout << ans << endl;
    }

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3812kb

input:

2
4
5 2 2 6
5
1 5 4 4 1

output:

33
29

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 350ms
memory: 4008kb

input:

10000
4
5 2 2 6
5
1 5 4 4 1
197
763787596 15221694 898228999 187472305 466351873 822742732 437754202 800092772 843092246 915675776 166265020 346340615 796714085 497548541 182089610 64356048 363276768 181268733 257949015 236568898 752096761 928725929 443146784 114577469 833053207 38120723 14891030 41...

output:

33
29
222270467438
350318080026
314692266040
457356525366
294140780287
465641964838
350585524645
383231239130
221538550827
366951118622
267574209310
183998247460
584551719150
110529307975
336548832140
295220647597
346331365342
330759837765
299646768960
462452107352
500817950159
448651251618
26321500...

result:

wrong answer 3rd lines differ - expected: '382465638565', found: '222270467438'