답안 #246847

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
246847 2020-07-10T12:10:50 Z kimbj0709 Toll (BOI17_toll) C++14
0 / 100
797 ms 196724 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
#define sqrtn 230
#define maxn 50050
#define mxdist 500000000
vector<int> jump = {0,40,40,40,40,40};
int dist[maxn][231];
int k,no_of_vertex,no_of_edge,no_of_query;
vector<int> top;
vector<int> visited(maxn,0);
vector<vector<pair<int,int> > > adj(maxn);
vector<int> ipos(maxn,0);
void topsort(int node){
    visited[node] = 1;
    for(auto k:adj[node]){
        if(visited[k.f]==1){
            continue;
        }
        topsort(k.f);
    }
    top.push_back(node);
}
void find(int node){
  vector<pair<int,int> > curr;
  vector<int> distt(231,INT_MAX);
  for(int i=node;i<min(no_of_vertex,node+230);i++){
    curr.push_back({ipos[i],i});
  }
  distt[0] = 0;
  sort(curr.begin(),curr.end());
  for(int i=0;i<curr.size();i++){
    for(auto kk:adj[curr[i].s]){
      if(kk.f>node+230){
        continue;
      }
      distt[kk.f-node] = min(distt[kk.f-node],distt[curr[i].s-node]+kk.s);
    }
  }
  for(int i=0;i<231;i++){
    dist[node][i] = INT_MAX;
  }
  for(int i=0;i<curr.size();i++){
    dist[node][i] = distt[i];
  }
  return;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
  cin >> k >> no_of_vertex >> no_of_edge >> no_of_query;
  int input1,input2,input3;
  for(int i=0;i<no_of_edge;i++){
    cin >> input1 >> input2 >> input3;
    adj[input1].push_back({input2,input3});
  }
  for(int i=0;i<no_of_vertex;i++){
    if(visited[i]==0){
      topsort(i);
    }
  }
  reverse(top.begin(),top.end());
  for(int i=0;i<top.size();i++){
    ipos[top[i]] = i;
  }
  for(int i=0;i<no_of_vertex;i++){
    find(i);
  }
  for(int i=0;i<no_of_query;i++){
    cin >> input1 >> input2;
    vector<int> currdist(k,0);
    if(input1+230>=input2){
      if(dist[input1][input2-input1]>=INT_MAX){
        cout << -1 << "\n";
      }
      else{
        cout << dist[input1][input2-input1] << "\n";
      }
      continue;
    }
    int q = input1/k;
    q++;
    for(int j=0;j<k;j++){
      currdist[j] = dist[input1][q*k+j-input1];
    }
    while(1){
      if(q*k+230>=input2){
        int mini = INT_MAX;
        for(int j=0;j<k;j++){
          if(input2-q*k-j<0){
            continue;
          }
          mini = min(mini,dist[q*k+j][input2-q*k-j]);
        }
        if(mini==INT_MAX){
          cout << -1 << "\n";
        }
        else{
          cout << mini << "\n";
        }
        break;
      }
      vector<int> next(k,INT_MAX);
      for(int j=0;j<k;j++){
        for(int a=j;a<k;a++){
          next[a] = min(next[a],dist[q*k+j][q*jump[k]+a-j]);
        }
      }
      currdist = next;
      q += jump[k];
    }
  }
 
}

Compilation message

toll.cpp: In function 'void find(long long int)':
toll.cpp:34:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<curr.size();i++){
               ~^~~~~~~~~~~~
toll.cpp:45:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<curr.size();i++){
               ~^~~~~~~~~~~~
toll.cpp: In function 'int32_t main()':
toll.cpp:65:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<top.size();i++){
               ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 667 ms 196724 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 797 ms 195036 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2304 KB Output is correct
2 Correct 6 ms 2304 KB Output is correct
3 Correct 6 ms 2304 KB Output is correct
4 Correct 6 ms 2304 KB Output is correct
5 Correct 5 ms 2304 KB Output is correct
6 Correct 17 ms 4224 KB Output is correct
7 Incorrect 20 ms 4264 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2304 KB Output is correct
2 Correct 6 ms 2304 KB Output is correct
3 Correct 6 ms 2304 KB Output is correct
4 Correct 6 ms 2304 KB Output is correct
5 Correct 5 ms 2304 KB Output is correct
6 Correct 17 ms 4224 KB Output is correct
7 Incorrect 20 ms 4264 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 667 ms 196724 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -