QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#262261#6134. Soldier GamefexlaRE 1ms3552kbC++141.9kb2023-11-23 17:15:252023-11-23 17:15:26

Judging History

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

  • [2023-11-23 17:15:26]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3552kb
  • [2023-11-23 17:15:25]
  • 提交

answer

//
// Created by admin on 2023/11/23.
//
#include <bits/stdc++.h>

using namespace std;
int t;
typedef long long ll;
typedef pair<ll, ll> pl;

vector<pl> dp[2]{{},
                 {}};

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    if(n == 1 || n == 2) {
        cout << "0\n";
        return;
    }
    dp[0] = {};
    dp[1] = {};
    dp[0].push_back({a[0], a[0]});
    dp[1].push_back({min(a[0], a[1]), max(a[0], a[1])});
    dp[1].push_back({a[0] + a[1], a[0] + a[1]});
    for (int i = 2; i < n; ++i) {
        vector<pl> tmp{};
        for (int ind = 0; ind < 2; ++ind) {
            ll v = ind == 0 ? (a[i] + a[i - 1]) : a[i];
            for (int j = 0; j < dp[ind].size(); ++j) {
                pl p = dp[ind][j];
                p.first = min(p.first, v);
                p.second = max(p.second, v);
                tmp.push_back(p);
            }
        }
        std::sort(tmp.begin(), tmp.end(),
                  [](pl p1, pl p2) {
                      if(p1.first < p2.first)return true;
                      return p1.second > p2.second;
                  }
        );

        vector<pl> dp_cur{};
        ll r = 1e18;
        for (int j = tmp.size() - 1; j >= 0; --j) {
            if(tmp[j].second >= r) {
                continue;
            }
            dp_cur.push_back(tmp[j]);
            r = tmp[j].second;
        }
        swap(dp[0], dp[1]);
//        dp[0] = dp[1];
        dp[1] = std::move(dp_cur);
    }
    ll ans = 1e12;
    for (auto &i: dp[1]) {
        ll dif = i.second - i.first;
        ans = min(ans, dif);
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(10) << fixed;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3552kb

input:

3
5
-1 4 2 1 1
4
1 3 2 4
1
7

output:

1
2
0

result:

ok 3 number(s): "1 2 0"

Test #2:

score: -100
Runtime Error

input:

10010
1
1000000000
1
-1000000000
2
1000000000 -1000000000
4
1000000000 1000000000 -1000000000 -1000000000
3
100 -100 100
16
-17 91 -19 66 100 -70 -71 76 -58 99 52 19 25 -67 -63 -32
7
-95 -26 63 -55 -19 77 -100
17
-100 72 -53 -32 8 -100 53 44 -100 -65 -81 -59 100 100 57 -47 1
11
99 10 -100 3 32 2 -26...

output:

0
0
0
2000000000
100
135
103
181
189
84
63
164
176
0
147
135
152
36
200
131
134
0
136
0
72
171
146
0
183
77
176
89
200
135
38
109
119
126
158
203
70
0
38
999804364
188
161
0
116
116
200
0
101
200
39
0
183
139
0
183
107
139
0
178
85993
126
153
168
163
96
104
96
52
126
47
130
79
0
123
188
173
33
0
83
...

result: