QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#113755 | #6627. Line Town | 1kri# | 0 | 4ms | 21308kb | C++14 | 980b | 2023-06-19 10:39:37 | 2024-05-31 14:06:47 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
#define inf 1000000000000000000ll
using namespace std;
int n;
int _abs(int x){
if (x<0)return -x;
return x;
}
struct node{
int p,v;
bool operator <(const node &y)const{
return _abs(v)<_abs(y.v);
}
}a[1000005];
ll f[1000005][2];
ll dfs(int now,int o){
if (f[now][o]!=-1)return f[now][o];
if (now==0)return 0;
int c0=0,c1=0;
for (int i=1;i<now;i++)
if (a[i].p>a[now].p)c0++;
else c1++;
int f0=1,f1=1;
if (o==1)f0=-1;
if (((now&1)^1^o)==1)f1=-1;
ll ans=inf;
if (a[now].p*f0<=0)ans=min(ans,c0+dfs(now-1,(o^1)));
if (a[now].p*f1>=0)ans=min(ans,c1+dfs(now-1,o));
return f[now][o]=ans;
}
int main(){
scanf("%d",&n);
for (int i=1;i<=n;i++){
a[i].p=i;
scanf("%d",&a[i].v);
if (i&1)a[i].v=-a[i].v;
}
sort(a+1,a+1+n);
memset(f,-1,sizeof(f));
ll ans=dfs(n,1);
if (ans==inf)ans=-1;
cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Accepted
time: 4ms
memory: 21308kb
input:
10 1 1 1 1 1 -1 -1 -1 1 -1
output:
-1
result:
ok 1 number(s): "-1"
Test #2:
score: -3
Wrong Answer
time: 0ms
memory: 19656kb
input:
10 1 1 1 1 1 1 -1 1 1 -1
output:
-1
result:
wrong answer 1st numbers differ - expected: '3', found: '-1'
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: 4
Accepted
time: 0ms
memory: 20624kb
input:
10 3 10 5 -9 7 2 -6 1 8 0
output:
-1
result:
ok 1 number(s): "-1"
Test #61:
score: -4
Wrong Answer
time: 0ms
memory: 20116kb
input:
10 -9 0 -1 7 5 10 6 3 2 -8
output:
-1
result:
wrong answer 1st numbers differ - expected: '13', found: '-1'
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Skipped
Dependency #1:
0%