結果
| 問題 |
No.704 ゴミ拾い Medium
|
| コンテスト | |
| ユーザー |
夕叢霧香(ゆうむらきりか)
|
| 提出日時 | 2018-01-28 12:57:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 118 ms / 1,500 ms |
| コード長 | 1,109 bytes |
| コンパイル時間 | 745 ms |
| コンパイル使用メモリ | 70,144 KB |
| 実行使用メモリ | 9,216 KB |
| 最終ジャッジ日時 | 2024-12-29 12:35:06 |
| 合計ジャッジ時間 | 5,167 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 44 |
ソースコード
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)
struct MinBIT {
static const int SIZE = 1 << 17;
static const int INFINITY = (1 << 30) - 1;
int bit[SIZE];
MinBIT() {
rep(i,SIZE)bit[i]=INFINITY;
}
void update(int x, int value) {
while(x<SIZE){
bit[x]=min(bit[x],value);
x+=x&(-x);
}
}
int query(int x) const {
int y = INFINITY;
while(x>0){
y=min(y,bit[x]);
x&=x-1;
}
return y;
}
};
int a[300001],x[300001],y[300001];
int dp[300001];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
rep(i,n)cin>>a[i];
rep(i,n)cin>>x[i];
rep(i,n)cin>>y[i];
MinBIT m1;
MinBIT p1;
rep(i,n){
// update
m1.update(100001-x[i],x[i]+y[i]+dp[i]);
p1.update(1+x[i],-x[i]+y[i]+dp[i]);
// query
int ans=1e9;
int curA=a[i];
ans=min(ans,m1.query(100001-curA)-curA);
ans=min(ans,p1.query(curA+1)+curA);
dp[i+1]=ans;
}
cout<<dp[n]<<endl;
}
夕叢霧香(ゆうむらきりか)