QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#688847#6443. Windblume FestivalStarrykillerWA 140ms3844kbC++231.1kb2024-10-30 13:56:162024-10-30 13:56:18

Judging History

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

  • [2024-10-30 13:56:18]
  • 评测
  • 测评结果:WA
  • 用时:140ms
  • 内存:3844kb
  • [2024-10-30 13:56:16]
  • 提交

answer

// Homura Akemi a.k.a. Starrykiller (/user/235125)
// I love Madoka Kaname forever! 
#include <bits/stdc++.h>

using namespace std;

template<typename L, typename R>
auto range(L l, R r) { return views::iota(l,r); }
auto rev=views::reverse;

template<typename T>
_GLIBCXX_ALWAYS_INLINE void chmax(T &a, T b) { a=max(a,b); }
template<typename T>
_GLIBCXX_ALWAYS_INLINE void chmin(T &a, T b) { a=min(a,b); }
int x=0x7fffffff;
#define int long long

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
int T; cin>>T;
// int T=1;
while (T--) []{
    int n; cin>>n;
    vector<int> a(n);
    for (auto &i: a) cin>>i;
    if (n==1) {
        cout<<a[0]<<'\n';
        return;
    }
    if (n==2) {
        cout<<max({a[0]+a[1],a[0]-a[1],a[1]-a[0]})<<'\n';
        return;
    }
    array<int,2> f{};
    f[0]=a[0]; f[1]=-a[0];
    for (auto i: range(1,n)) {
        decltype(f) g{}; g[0]=g[1]=-1e18;
        chmax(g[0],f[0]+a[i]);
        chmax(g[1],f[0]-a[i]);
        chmax(g[1],f[1]+a[i]);
        chmax(g[1],f[1]-a[i]);
        swap(f,g);
    }
    cout<<f[1]<<'\n';
}();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
4
1 -3 2 -4
11
91 66 73 71 32 83 72 79 84 33 93
12
91 66 73 71 32 83 72 79 84 33 33 93
13
91 66 73 71 32 83 72 79 84 33 33 33 93
1
0

output:

10
713
746
779
0

result:

ok 5 number(s): "10 713 746 779 0"

Test #2:

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

input:

1000000
1
2
1
-2
1
1
1
-1
1
2
1
1
1
2
1
-2
1
-2
1
2
1
1
1
1
1
2
1
2
1
2
1
-2
1
-2
1
0
1
2
1
1
1
-1
1
0
1
-2
1
0
1
1
1
1
1
-2
1
-2
1
2
1
1
1
2
1
1
1
1
1
0
1
2
1
0
1
-1
1
-1
1
-2
1
-2
1
0
1
-2
1
0
1
1
1
-1
1
2
1
0
1
-2
1
-2
1
0
1
1
1
-1
1
-2
1
-1
1
0
1
-1
1
-1
1
-1
1
-1
1
1
1
2
1
0
1
0
1
-2
1
2
1
2
1
...

output:

2
-2
1
-1
2
1
2
-2
-2
2
1
1
2
2
2
-2
-2
0
2
1
-1
0
-2
0
1
1
-2
-2
2
1
2
1
1
0
2
0
-1
-1
-2
-2
0
-2
0
1
-1
2
0
-2
-2
0
1
-1
-2
-1
0
-1
-1
-1
-1
1
2
0
0
-2
2
2
-1
2
-2
-1
-2
-1
-2
2
-1
-1
0
-2
0
0
0
1
1
2
1
-1
0
-2
1
2
1
1
0
1
2
-2
-1
-1
0
-2
2
2
1
0
-1
0
-1
0
1
-2
2
1
-2
-2
0
-1
1
-1
2
-2
2
1
1
2
0
2...

result:

ok 1000000 numbers

Test #3:

score: 0
Accepted
time: 140ms
memory: 3620kb

input:

1000000
1
-182188011
1
-889401027
1
-379434063
1
-731536137
1
632523155
1
837208235
1
192807861
1
-162604370
1
963735146
1
736725265
1
-70315400
1
659481275
1
217883785
1
-396219883
1
653358757
1
-489133046
1
412498823
1
-210628961
1
-137310415
1
849916587
1
-50143945
1
-509463528
1
105005776
1
7382...

output:

-182188011
-889401027
-379434063
-731536137
632523155
837208235
192807861
-162604370
963735146
736725265
-70315400
659481275
217883785
-396219883
653358757
-489133046
412498823
-210628961
-137310415
849916587
-50143945
-509463528
105005776
738262345
352827098
391146170
108054338
601933024
-705538291...

result:

ok 1000000 numbers

Test #4:

score: -100
Wrong Answer
time: 88ms
memory: 3560kb

input:

666685
1
0
2
2 -1
1
2
1
2
1
-1
2
-2 2
1
0
2
-1 -2
2
2 -1
2
0 1
2
2 -1
1
1
2
1 1
1
1
2
0 2
2
1 0
2
0 2
2
-1 2
1
1
1
-1
1
-2
1
2
2
-1 0
2
-2 1
2
-2 -2
2
0 -1
1
-2
1
2
1
2
2
-1 -1
1
1
1
-2
1
2
2
-2 1
2
2 1
2
0 -2
1
-1
1
0
1
2
1
-2
2
2 0
1
-1
2
0 0
2
2 -2
2
-2 0
1
-2
1
1
2
2 0
1
-2
1
-1
2
1 -1
2
1 -2
2
...

output:

0
3
2
2
-1
4
0
1
3
1
3
1
2
1
2
1
2
3
1
-1
-2
2
1
3
0
1
-2
2
2
0
1
-2
2
3
3
2
-1
0
2
-2
2
-1
0
4
2
-2
1
2
-2
-1
2
3
2
-2
3
4
2
2
-2
1
2
3
3
2
2
2
2
-2
2
1
1
0
2
-1
2
0
4
2
1
2
4
1
3
4
-2
-1
3
3
0
1
1
0
-2
2
1
2
2
1
2
-2
0
2
2
3
2
-1
0
-2
0
-1
2
0
3
1
2
-1
0
1
2
0
-1
3
-1
2
0
1
-1
-1
-2
1
0
2
1
-2
2
2...

result:

wrong answer 13th numbers differ - expected: '0', found: '2'