QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#117245#6627. Line Townpandapythoner#0 1ms3640kbC++201.3kb2023-06-30 19:18:302024-05-31 18:43:36

Judging History

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

  • [2024-05-31 18:43:36]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3640kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-30 19:18:30]
  • 提交

answer

#include <bits/stdc++.h>


using namespace std;


#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()


mt19937 rnd(234);
const ll inf = 1e18;


int n;
vector<ll> h;


ll solve_abs_1(){
    vector<int> a(n + 2);
    a[0] = 0;
    a[n + 1] = 1;
    for(int i = 0; i < n; i += 1){
        if(h[i] < 0){
            a[i + 1] = 0;
        } else{
            a[i + 1] = 1;
        }
    }
    vector<int> d(n + 1);
    for(int i = 0; i <= n; i += 1){
        d[i] = (a[i] ^ a[i + 1]);
    }
    vector<int> stck;
    int rs = 0;
    for(int i = 0; i <= n; i += 1){
        if(d[i]){
            if(!stck.empty() && stck.back() % 2 == i % 2){
                rs += (i - stck.back()) / 2;
                stck.pop_back();
            } else{
                stck.push_back(i);
            }
        }
    }
    if((int)stck.size() != 1){
        return -1;
    }
    return rs;
}


int32_t main(){
    if(1){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }
    cin >> n;
    h.resize(n);
    for(int i = 0; i < n; i += 1){
        cin >> h[i];
    }
    cout << solve_abs_1() << "\n";
    return 0;
}

/*
4
1 -1 1 -1

4
1 1 -1 -1

*/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 3
Accepted
time: 1ms
memory: 3576kb

input:

10
1 1 1 1 1 -1 -1 -1 1 -1

output:

-1

result:

ok 1 number(s): "-1"

Test #2:

score: 0
Wrong Answer
time: 1ms
memory: 3640kb

input:

10
1 1 1 1 1 1 -1 1 1 -1

output:

4

result:

wrong answer 1st numbers differ - expected: '3', found: '4'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Wrong Answer

Test #60:

score: 0
Wrong Answer
time: 0ms
memory: 3616kb

input:

10
3 10 5 -9 7 2 -6 1 8 0

output:

3

result:

wrong answer 1st numbers differ - expected: '-1', found: '3'

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #3:

0%

Subtask #8:

score: 0
Skipped

Dependency #1:

0%