Submission #856452


Source Code Expand

Copy
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <list>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(d) string(1,d)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007
 
ll d[1005][1005];

#define MAX_V 1005
#define INF 1000000000

struct edge{int to, cost;};
typedef pair<int,int> P;

vector<edge> G[MAX_V];
int mn[MAX_V];

void ae(int from, int to, int cost){
  edge e = {to,cost};
  G[from].push_back(e);
}

void dijk(int start, int V){
  priority_queue<P, vector<P>, greater<P> > que;
  for(int i = 0; i < V; i++)mn[i] = INF;
  mn[start] = 0;
  que.push(P(0,start));
  while(!que.empty()){
    P p = que.top(); que.pop();
    int v = p.second;
    if(mn[v]<p.first)continue;
    for(int i = 0; i < G[v].size(); i++){
      edge e = G[v][i];
      if(mn[e.to] > mn[v]+e.cost){
        mn[e.to] = mn[v]+e.cost;
        que.push(P(mn[e.to],e.to));
      }
    }
  }
}

 
int main() {
  ll n;
  cin>>n;
  vector<ll> v;
  rep(i,0,n){
    ll a;
    cin>>a;
    v.pb(a);
  }
  ll l,q;
  cin>>l>>q;
  vector<pair<ll,ll> > vq;
  rep(i,0,q){
    ll a,b;
    cin>>a>>b;
    a--;
    b--;
    vq.pb(mp(min(a,b),max(a,b)));
  }
  if(n>1000||q>1000)return 0;
  clr(d,0);
  rep(i,0,v.sz){
    rep(j,i+1,v.sz){
      if(v[j]-v[i]<=l){
        ae(i,j,1);
      }
    }
  }
  rep(i,0,q){
    ll a = vq[i].fi;
    ll b = vq[i].se;
    dijk(a,v.sz);
    cout << mn[b] << endl;
  }
  return 0;
}

Submission Info

Submission Time
Task E - Tak and Hotels
User nmnmnmnmnmnmnm
Language C++14 (GCC 5.4.1)
Score 200
Code Size 2050 Byte
Status WA
Exec Time 802 ms
Memory 13440 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 200 / 200 0 / 500
Status
AC × 1
AC × 14
AC × 14
WA × 13
Set Name Test Cases
Sample example_01.txt
Subtask1 example_01.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt
All example_01.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask2_13.txt
Case Name Status Exec Time Memory
example_01.txt AC 15 ms 8192 KB
subtask1_01.txt AC 15 ms 8192 KB
subtask1_02.txt AC 14 ms 8192 KB
subtask1_03.txt AC 78 ms 8320 KB
subtask1_04.txt AC 44 ms 8192 KB
subtask1_05.txt AC 250 ms 9216 KB
subtask1_06.txt AC 27 ms 8192 KB
subtask1_07.txt AC 82 ms 8704 KB
subtask1_08.txt AC 802 ms 13440 KB
subtask1_09.txt AC 74 ms 8320 KB
subtask1_10.txt AC 50 ms 8192 KB
subtask1_11.txt AC 49 ms 8192 KB
subtask1_12.txt AC 49 ms 8192 KB
subtask1_13.txt AC 46 ms 8192 KB
subtask2_01.txt WA 177 ms 3188 KB
subtask2_02.txt WA 183 ms 3188 KB
subtask2_03.txt WA 193 ms 3188 KB
subtask2_04.txt WA 119 ms 1912 KB
subtask2_05.txt WA 118 ms 1912 KB
subtask2_06.txt WA 182 ms 3188 KB
subtask2_07.txt WA 184 ms 3188 KB
subtask2_08.txt WA 175 ms 3188 KB
subtask2_09.txt WA 180 ms 3188 KB
subtask2_10.txt WA 178 ms 3188 KB
subtask2_11.txt WA 186 ms 3188 KB
subtask2_12.txt WA 163 ms 3188 KB
subtask2_13.txt WA 172 ms 3188 KB