結果

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

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#define ll long long
using namespace std;
typedef struct tga{
  int s,t,y,m;
} tga;
int main(){
  int N,C,V,numCount=0,ansTime=-1;
  cin>>N>>C>>V;
  vector<int> st,yst,mst,ist;
  vector<tga> v(V);
  vector<int> goty(V+1,0),gotm(V+1,0);

  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){
        yst.push_back(v[i].y);
        mst.push_back(v[i].m);
        if(goty[i]!=0&&gotm[i]!=0&&
        accumulate(mst.begin(),mst.end(),0)>gotm[i]&&
        accumulate(yst.begin(),yst.end(),0)>goty[i]){
          yst.pop_back();
          mst.pop_back();
          continue;
        }
        gotm[i]=accumulate(mst.begin(),mst.end(),0);
        goty[i]=accumulate(yst.begin(),yst.end(),0);
        st.push_back(v[i].s);
        ist.push_back(i);
        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("%d",ansTime);
}
0