結果

問題 No.1 道のショートカット
ユーザー programvx
提出日時 2018-12-22 01:10:39
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 1,547 bytes
コンパイル時間 791 ms
コンパイル使用メモリ 72,716 KB
実行使用メモリ 10,016 KB
最終ジャッジ日時 2024-07-08 05:07:32
合計ジャッジ時間 7,261 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 4 TLE * 1 -- * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#define ll long long
using namespace std;
typedef struct tga{
  ll s,t,y,m;
} tga;
int main(){
  ll N,C,V,numCount=0,ansTime=-1;
  cin>>N>>C>>V;
  vector<ll> st,yst,mst,ist;
  vector<tga> v(V);
  for(int i=0;i<V;i++){
      cin>>v[i].s;
    }
  for(int i=0;i<V;i++){
      cin>>v[i].t;
    }
  for(int i=0;i<V;i++){
      cin>>v[i].y;
    }
  for(int i=0;i<V;i++){
      cin>>v[i].m;
    }
    sort(v.begin(),v.end(),
    [](const tga& a,const tga& b) {return a.t< b.t;});

    st.push_back(N);


    for(int i=0;;i++){
      if(st[st.size()-1]==v[i].t){
        st.push_back(v[i].s);
        ist.push_back(i);
        yst.push_back(v[i].y);
        mst.push_back(v[i].m);
        i=-1;
      }
      else if(st[st.size()-1]==1){
        if(C>=accumulate(yst.begin(),yst.end(),0)){
          if(ansTime==-1){
            ansTime=accumulate(mst.begin(),mst.end(),0);
          }
          else{
            if(ansTime>accumulate(mst.begin(),mst.end(),0))
            ansTime=accumulate(mst.begin(),mst.end(),0);
          }
        }
        numCount++;
        st.pop_back();
        i=ist[ist.size()-1];
        ist.pop_back();
        yst.pop_back();
        mst.pop_back();
      }
      else if(v[i].t>st[st.size()-1]){
        if(st[st.size()-1]==N)
        break;
        st.pop_back();
        i=ist[ist.size()-1];
        ist.pop_back();
        yst.pop_back();
        mst.pop_back();
      }
    }
printf("%lld",ansTime);
}
0