Submission #423722

# Submission time Handle Problem Language Result Execution time Memory
423722 2021-06-11T11:54:26 Z kai824 Treatment Project (JOI20_treatment) C++17
0 / 100
3000 ms 6084 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long
const int mxm=100005,inf=1e17;
int t[mxm],l[mxm],r[mxm],c[mxm];
vector<int> adj[mxm];
int dist[mxm];bool vis[mxm];

void main1(int n,int m){
  ;
}

int32_t main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int n,m;
  cin>>n>>m;
  //funny how subtasks 1-3 can be done with dijkstra, and ST4 is... 2d segtree with lazy nodes? idk
  //if(m>5000)main1(n,m);

  for(int i=0;i<m;i++){
    cin>>t[i]>>l[i]>>r[i]>>c[i];
    if(l[i]==1)adj[m].push_back(i);
    if(r[i]==n)adj[i].push_back(m+1);
  }c[m]=c[m+1]=0;
  
  for(int i=0;i<m;i++){
    for(int j=i+1;j<m;j++){
      //cout<<"Iteration "<<i<<' '<<j<<'\n';
      if(t[i]>t[j])swap(i,j);//ensures t[j]>=t[i]
      int a,b;
      a=l[i]+t[j]-t[i];
      b=r[i]-t[j]+t[i];
      if(l[i]==1)a=1;
      if(r[i]==n)b=n;
      bool bit=false;
      if(a>b)goto end;
      //compare range [a,b] with [l[j],r[j]]
      b++;r[j]++;
      if(l[j]<=b && b<=r[j]){
        bit=true;
        // cout<<"PATH1 "<<a<<' '<<b<<' '<<l[j]<<' '<<r[j]<<'\n';
        // cout<<i<<' '<<j<<'\n';
      }else if(a<=r[j] && r[j]<=b){
        bit=true;
      }else if(a<=l[j] && l[j]<=b)bit=true;
      else if(l[j]<=a && a<=r[j])bit=true;
      if(bit){adj[i].push_back(j);adj[j].push_back(i);}
      b--;r[j]--;
      end:;
      if(i>j)swap(i,j);
    }
  }
  for(int i=0;i<m+2;i++)dist[i]=inf;
  dist[m]=0;

  while(true){
    int a=-1;
    for(int i=0;i<m+2;i++){
      if(vis[i])continue;
      if(a==-1 || dist[i]<dist[a])a=i;
    }
    if(a==-1)break;
    vis[a]=true;
    for(int x:adj[a]){
      dist[x]=min(dist[x],dist[a]+c[x]);
    }
  }

  if(dist[m+1]==inf)cout<<"-1\n";
  else cout<<dist[m+1]<<'\n';
}
# Verdict Execution time Memory Grader output
1 Execution timed out 3073 ms 6084 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Incorrect 2 ms 2692 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Incorrect 2 ms 2692 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3073 ms 6084 KB Time limit exceeded
2 Halted 0 ms 0 KB -