QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#100300#4647. Wavy Treeeuphria#WA 249ms18880kbC++201.4kb2023-04-25 15:26:512023-04-25 15:26:52

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-25 15:26:52]
  • 评测
  • 测评结果:WA
  • 用时:249ms
  • 内存:18880kb
  • [2023-04-25 15:26:51]
  • 提交

answer

//B站关注 艾尔莎 喵
//All OK
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define ios ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(0);cout << fixed << setprecision(9)
#define INF 1ll*1e10
#define LNF (1ll << 60)
#define PII pair<int, int>
#define PI acos(-1)
#define ll long long
// #define ll __int128 
#define int ll
#define endl '\n'
using namespace std;

const int N = 1e6 + 10;
int n;
ll a[N], b[N]; 

void solve(){
    ll ans = INF;
    cin >> n;
    for(int i = 1; i <= n; i ++)
        cin >> a[i];
    b[1] = a[1];
    ll res = 0;
    for(int i = 2; i <= n; i ++){
        b[i] = a[i];
        if(i % 2 && b[i - 1] <= b[i])
            res += b[i] - b[i - 1] + 1, b[i] = b[i - 1] - 1;
        else if(i % 2 == 0 && b[i - 1] >= b[i])
            res += b[i - 1] - b[i] + 1, b[i] = b[i - 1] + 1;
    }
    ans = min(ans, res);

    res = 0;
    for(int i = 2; i <= n; i ++){
        b[i] = a[i];
        if(i % 2 && b[i - 1] >= b[i])
            res += b[i - 1] - b[i] + 1, b[i] = b[i - 1] + 1;
        else if(i % 2 == 0 && b[i - 1] <= b[i])
            res += b[i] - b[i - 1] + 1, b[i] = b[i - 1] - 1;
    }
    cout << min(ans, res) << endl;
}   

signed main(){
    ios;

    // init();
    int _ = 1;
    cin >> _;
    for(int __ = 1; __ <= _; __ ++){
        // cout << "Case " << __ << ": ";
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 249ms
memory: 18880kb

input:

1000
100000
421811673 163389757 362117917 679743722 325614744 632629964 980475526 100505548 936347880 928352466 107919751 93875425 790807861 179598820 105172240 143240481 781447901 225995680 495635141 806359893 572331818 169913092 230473678 658931041 285082875 709115692 204427990 675460241 498216193...

output:

10000000000
10000000000
10000000000
10000000000
10000000000
10000000000
10000000000
10000000000
10000000000
10000000000
10000000000
10000000000
10000000000
10000000000
10000000000
4819422928
10000000000
10000000000
10000000000
10000000000
10000000000
10000000000
10000000000
10000000000
10000000000
1...

result:

wrong answer 1st lines differ - expected: '7254088195794', found: '10000000000'