QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#190307#6134. Soldier GamewoshiluoWA 279ms14520kbC++201.6kb2023-09-28 16:57:172023-09-28 16:57:18

Judging History

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

  • [2023-09-28 16:57:18]
  • 评测
  • 测评结果:WA
  • 用时:279ms
  • 内存:14520kb
  • [2023-09-28 16:57:17]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;


void solve() {

    int n;
    cin >> n;
    
    vector<int> a(n);
    for (int i = 0; i < n; i++) 
        cin >> a[i];
    vector<array<long long, 3>> aa;
    for (int i = 0; i < n; i++)
        aa.emplace_back(array<long long, 3>{a[i], i, 0});
        
    for (int i = 0; i + 1 < n; i++)
        aa.emplace_back(array<long long, 3>{a[i] + a[i + 1], i, 1});
       
    sort(aa.begin(), aa.end());
    
    
    vector<array<array<int, 2>, 2>> t(n * 2);
    for (int i = 0; i < n; i++)
        t[i + n][1][0] = 1;
    auto update = [&](int x) {
        for (int i = 0; i < 2; i++)
            for (int j = 0; j < 2; j++) {
                t[x][i][j] = 0;
                for (int k = 0; k < 2; k++)
                    t[x][i][j] |= t[x * 2][i][k] & t[x * 2 + 1][k][j];
            }
    };
    
    
    auto upd = [&](int x, int c, bool k) {
        x += n;
        t[x][0][c] = k;
        while (x >>= 1)
            update(x);
    };
    int j = -1;
    long long mn = 2e18 + 1;
    for (int i = 0; i < n * 2 - 1; i++) {
        auto [v, x, c] = aa[i];
        upd(x, c, 1);
        while (j + 1 < n * 2 - 1 && t[1][0][0]) {
            auto [v2, x2, c2] = aa[j + 1];
            upd(x2, c2, 0);
            j += 1;
        }
        if (j >= 0)
        	mn = min(mn, v - aa[j][0]);
    }
    
    cout << mn << "\n";
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
        solve();
        
    return 0;
}

/*

1
4
1000000000 1000000000 -1000000000 -1000000000

*/

詳細信息

Test #1:

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

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
Wrong Answer
time: 279ms
memory: 14520kb

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
163
164
176
0
147
135
152
136
200
131
134
0
136
0
72
171
146
0
183
77
176
89
200
135
38
163
119
126
196
189
70
0
38
999804364
188
161
0
116
124
200
0
101
200
39
0
183
139
0
200
107
153
0
178
85993
199
153
168
163
96
53
107
52
126
47
130
79
0
123
188
173
33
0
8...

result:

wrong answer 11th numbers differ - expected: '63', found: '163'