Submission #8366900


Source Code Expand

Copy
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);
#if __cplusplus>=201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, long long M, std::vector<long long> L, std::vector<long long> R, std::vector<long long> C){
  priority_queue<pll,vector<pll>,greater<pll>> q;
  q.push(pll(0,1));
  vector<pair<pll,ll>> v(M);
  REP(M)v[i]=make_pair(pll(L[i],C[i]),R[i]);
  sort(v.begin(),v.end());
  dump(v);
  REP(M){
    while(!q.empty()&&q.top().second<v[i].first.first){
      q.pop();
    }
    if(q.empty()){
      break;
    }
    if(q.top().second<v[i].second){
      ll tmp=q.top().first;
      q.push(pll(tmp+v[i].first.second,v[i].second));
    }
    dump(q.top());
  }
  while(!q.empty()&&q.top().second<N){
    q.pop();
  }
  if(q.empty()){
    cout<<-1<<endl;
  }else{
    cout<<q.top().first<<endl;
  }
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> L(M);
    std::vector<long long> R(M);
    std::vector<long long> C(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&L[i]);
        scanf("%lld",&R[i]);
        scanf("%lld",&C[i]);
    }
    solve(N, M, std::move(L), std::move(R), std::move(C));
    return 0;
}

Submission Info

Submission Time
Task D - Shortest Path on a Line
User jp3bgy
Language C++14 (GCC 5.4.1)
Score 600
Code Size 2248 Byte
Status AC
Exec Time 54 ms
Memory 6772 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:87:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&N);
                     ^
./Main.cpp:89:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&M);
                     ^
./Main.cpp:94:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",&L[i]);
                            ^
./Main.cpp:95:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",&R[i]);
                            ^
./Main.cpp:96:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",&C[i]);
                        ...

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 40
Set Name Test Cases
Sample sample01.txt, sample02.txt, sample03.txt
All sample01.txt, sample02.txt, sample03.txt, in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, sample01.txt, sample02.txt, sample03.txt
Case Name Status Exec Time Memory
in01.txt AC 2 ms 256 KB
in02.txt AC 2 ms 256 KB
in03.txt AC 2 ms 256 KB
in04.txt AC 2 ms 256 KB
in05.txt AC 2 ms 256 KB
in06.txt AC 2 ms 256 KB
in07.txt AC 40 ms 4992 KB
in08.txt AC 37 ms 4480 KB
in09.txt AC 48 ms 6772 KB
in10.txt AC 42 ms 5624 KB
in11.txt AC 49 ms 5752 KB
in12.txt AC 42 ms 5880 KB
in13.txt AC 50 ms 6008 KB
in14.txt AC 54 ms 6136 KB
in15.txt AC 49 ms 5752 KB
in16.txt AC 51 ms 5880 KB
in17.txt AC 45 ms 5880 KB
in18.txt AC 51 ms 5880 KB
in19.txt AC 34 ms 4608 KB
in20.txt AC 41 ms 4608 KB
in21.txt AC 44 ms 4992 KB
in22.txt AC 43 ms 4736 KB
in23.txt AC 43 ms 4736 KB
in24.txt AC 44 ms 4864 KB
in25.txt AC 40 ms 4992 KB
in26.txt AC 45 ms 5372 KB
in27.txt AC 32 ms 4864 KB
in28.txt AC 44 ms 5500 KB
in29.txt AC 43 ms 6008 KB
in30.txt AC 41 ms 5372 KB
in31.txt AC 35 ms 4736 KB
in32.txt AC 34 ms 4608 KB
in33.txt AC 39 ms 5120 KB
in34.txt AC 1 ms 256 KB
sample01.txt AC 1 ms 256 KB
sample02.txt AC 1 ms 256 KB
sample03.txt AC 1 ms 256 KB