Submission #4299147
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
const ll INF = (1LL<<60);
const ll MAX_N = 100005;
struct data{
map<ll,ll> dat[MAX_N];
void SetValue(ll a,ll b,ll val){
ll cb=b;
while(a<MAX_N){
b=cb;
while(b<MAX_N){
if( dat[a].count(b) == 0 )dat[a][b]=INF;
dat[a][b]=min(dat[a][b],val);
b+=(b&-b);
}
a+=(a&-a);
}
}
ll GetMin(ll a,ll b){
ll cb=b;
ll res=INF;
while(a){
b=cb;
while(b){
if( dat[a].count(b) == 0 )dat[a][b]=INF;
res=min(res,dat[a][b]);
b-=(b&-b);
}
a-=(a&-a);
}
return res;
}
};
data tree;
int N, si,ti;
vector<PP> t;
ll X[100005],Y[100005],C[100005], ID[100005];
ll dp[100005];
void solve(){
int sj;
int tj;
for(int i=0;i<N;i++){
if( ID[i] == si )sj = i;
if( ID[i] == ti )tj = i;
// cout<<X[i]<<' '<<Y[i]<<endl;
}
tree.SetValue( X[ sj ] , Y[ sj ] , C[ sj ] );
for(int i=sj;i<N;i++){
ll ans=tree.GetMin(X[i],Y[i]);
// cout<<i<<' '<<ans<<' '<<N<<endl;
if( i == tj ){
cout<<ans<<endl;
return;
}
dp[i]=ans;
tree.SetValue(X[i],Y[i],ans+C[i]);
}
}
int main(){
cin>>N>>si>>ti;
for(int i=0;i<N;i++){
cin>>X[i]>>Y[i]>>C[i];
t.push_back(PP(P(X[i],Y[i]),P(C[i],i)));
}
si--;
ti--;
sort(t.begin(),t.end());
for(int i=0;i<N;i++){
X[i]=t[i].first.first;
Y[i]=t[i].first.second;
C[i]=t[i].second.first;
ID[i]=t[i].second.second;
}
vector<ll> tmp;
for(int i=0;i<N;i++){
tmp.push_back(X[i]);
}
sort(tmp.begin(),tmp.end());
tmp.erase( unique( tmp.begin(), tmp.end()) , tmp.end() );
for(int i=0;i<N;i++){
X[i]=lower_bound( tmp.begin(), tmp.end(), X[i]) - tmp.begin()+1;
}
tmp.clear();
for(int i=0;i<N;i++){
tmp.push_back(Y[i]);
}
sort(tmp.begin(),tmp.end());
tmp.erase( unique( tmp.begin(), tmp.end()) , tmp.end() );
for(int i=0;i<N;i++){
Y[i]=lower_bound( tmp.begin(), tmp.end(), Y[i]) - tmp.begin()+1;
}
solve();
return 0;
}
Submission Info
| Submission Time |
|
| Task |
F - Flights |
| User |
dohatsutsu |
| Language |
C++14 (GCC 5.4.1) |
| Score |
0 |
| Code Size |
2230 Byte |
| Status |
WA |
| Exec Time |
2122 ms |
| Memory |
309612 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
0 / 900 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
sample-01.txt, sample-02.txt |
| All |
01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, sample-01.txt, sample-02.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 01-01.txt |
WA |
3 ms |
6784 KiB |
| 01-02.txt |
TLE |
2121 ms |
303960 KiB |
| 01-03.txt |
TLE |
2122 ms |
304236 KiB |
| 01-04.txt |
TLE |
2122 ms |
309612 KiB |
| 01-05.txt |
WA |
1950 ms |
207084 KiB |
| 01-06.txt |
WA |
125 ms |
13036 KiB |
| 01-07.txt |
WA |
1187 ms |
120024 KiB |
| 01-08.txt |
WA |
120 ms |
13036 KiB |
| 01-09.txt |
WA |
1856 ms |
197612 KiB |
| 01-10.txt |
WA |
1186 ms |
119020 KiB |
| 01-11.txt |
WA |
1880 ms |
200812 KiB |
| 01-12.txt |
WA |
1785 ms |
187372 KiB |
| 01-13.txt |
WA |
1184 ms |
119788 KiB |
| 01-14.txt |
WA |
1805 ms |
191724 KiB |
| 01-15.txt |
WA |
1954 ms |
209260 KiB |
| 01-16.txt |
WA |
121 ms |
13932 KiB |
| 01-17.txt |
WA |
121 ms |
13036 KiB |
| 01-18.txt |
WA |
1925 ms |
205292 KiB |
| 01-19.txt |
WA |
1188 ms |
120300 KiB |
| 01-20.txt |
WA |
541 ms |
62188 KiB |
| 01-21.txt |
WA |
616 ms |
70636 KiB |
| 01-22.txt |
WA |
230 ms |
26092 KiB |
| 01-23.txt |
WA |
476 ms |
50284 KiB |
| sample-01.txt |
WA |
3 ms |
6784 KiB |
| sample-02.txt |
WA |
3 ms |
6784 KiB |