QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#866776#9222. Price Combolyx123886a123886TL 0ms11472kbC++141.9kb2025-01-22 18:32:212025-01-22 18:32:21

Judging History

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

  • [2025-01-22 18:32:21]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:11472kb
  • [2025-01-22 18:32:21]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i) 
#define dec(i,a,b) for(int i=(a);i>=(b);--i) 
using ll=long long;
using pi=pair<int,int>;
using vi=vector<int>;
using vp=vector<pi>;
template<class T> bool chkmin(T &x,T y) {return (y<x)?(x=y,true):false;}
template<class T> bool chkmax(T &x,T y) {return (y>x)?(x=y,true):false;}
#define pb push_back
#define SZ(x) int(x.size())
#define fi first
#define se second
#define LOCAL 0
#define open_file if(LOCAL) {freopen("a.in","r",stdin);freopen("a.out","w",stdout);}
int read() {int x;scanf("%d",&x);return x;}

using info=array<array<ll,2>,2>;
void operator +=(info &x,const info &y) {
    rep(i,0,1) rep(j,0,1) chkmin(x[i][j],y[i][j]);
}
info operator +(info x,const info &y) {
    x+=y;return x;
}
ll getmin(const info &x) {return min(min(x[0][0],x[0][1]),min(x[1][0],x[1][1]));} 
void add1(info &x,const ll val) {
    // swap(x[0],x[1]);
    x[0][0]+=val,x[0][1]+=val;
    swap(x[0],x[1]);
}
void add2(info &x,const ll val) {
    x[0][0]+=val,x[1][0]+=val;
    swap(x[0][0],x[0][1]),swap(x[1][0],x[1][1]);
}

const int MAXN=2e5+50;
info dp[MAXN];
pi a[MAXN];
int n;
int sa[MAXN],rk[MAXN];

void solve() {
    n=read();
    rep(i,1,n) a[i].fi=read();
    rep(i,1,n) a[i].se=read();
    sort(a+1,a+1+n);
    rep(i,1,n) sa[i]=i;sort(sa+1,sa+1+n,[&](auto i,auto j){return a[i].se<a[j].se;});
    rep(i,1,n) rk[sa[i]]=i;
    memset(dp,60,sizeof(dp));
    rep(i,1,n+1) dp[i][0][0]=0;
    dec(id,n,1) {
        int pos=rk[id];
        int lval=a[id].se,rval=a[id].fi;
        //left::sec right:fir
        rep(i,pos+1,n+1) dp[pos]+=dp[i];
        rep(i,1,pos) add2(dp[i],lval);
        rep(i,pos+1,n+1) add1(dp[i],rval);
    }
    ll ans=1e18;
    rep(i,1,n+1) chkmin(ans,getmin(dp[i]));
    printf("%lld",ans);
}
int main() {
    open_file
    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

7
10 12 19 99 10 8 49
9 14 15 199 11 7 19

output:

131

result:

ok single line: '131'

Test #2:

score: 0
Accepted
time: 0ms
memory: 11348kb

input:

7
10 12 19 99 10 8 49
9 14 15 199 11 7 19

output:

131

result:

ok single line: '131'

Test #3:

score: -100
Time Limit Exceeded

input:

199913
1212731 2525164 3210261 2457211 1013738 1931420 923123 867112 762069 2108660 108920 2491869 867107 387025 2278045 574027 1661570 820133 1274150 2001346 779766 3305537 3000211 2418643 2108660 2001343 1074820 2754411 826712 3117447 1661569 338161 1849064 3007920 3057426 468078 3252798 1274146 4...

output:


result: