結果

提出番号 1013
提出者 test
言語 C++
提出日時 2017-08-11 01:42:59
問題名 (44)玉ねぎの収穫をするkotamanegi
結果 MLE
点数 0%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 AC 100% 87ms 129056KB
2 AC 100% 62ms 125968KB
3 AC 100% 126ms 153456KB
4 AC 100% 184ms 154912KB
5 AC 100% 157ms 141568KB
6 AC 100% 564ms 252256KB
7 AC 100% 20ms 101632KB
8 AC 100% 162ms 158304KB
9 AC 100% 138ms 154240KB
10 AC 100% 144ms 155440KB
11 AC 100% 115ms 146736KB
12 AC 100% 33ms 110064KB
13 AC 100% 275ms 171136KB
14 AC 100% 62ms 123456KB
15 MLE 0% 564ms 266672KB
16 AC 100% 33ms 105712KB
17 AC 100% 139ms 153552KB
18 AC 100% 141ms 155296KB
19 AC 100% 203ms 153136KB
20 AC 100% 24ms 104432KB

ソースコード

#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>

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(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=b-1int;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int h,w;
int gy,gx;
int dy[1000];
int dx[1000];
int yl,yr,xl,xr;

#define MAX_V 1000000
#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() {
  cin>>h>>w;
  cin>>gy>>gx;
  gy--;gx--;
  rep(i,0,h){
    int a;
    cin>>a;
    dy[i] = a;
  }
  rep(i,0,w){
    int a;
    cin>>a;
    dx[i] = a;
  }
  cin>>yl>>yr>>xl>>xr;
  yl--;yr--;xl--;xr--;
  rep(y,0,h-1){
    rep(x,0,w){
      if(yl<=y&&y<=yr&&xl<=x&&x<=xr)continue;
      ae(y*w+x,(y+1)*w+x,dx[x]);
    }
  }
  rep(y,1,h){
    rep(x,0,w){
      if(yl<=y&&y<=yr&&xl<=x&&x<=xr)continue;
      ae(y*w+x,(y-1)*w+x,dx[x]);
    }
  }
  rep(y,0,h){
    rep(x,0,w-1){
      if(yl<=y&&y<=yr&&xl<=x&&x<=xr)continue;
      ae(y*w+x,y*w+x+1,dy[y]);
    }
  }
  rep(y,0,h){
    rep(x,1,w){
      if(yl<=y&&y<=yr&&xl<=x&&x<=xr)continue;
      ae(y*w+x,y*w+x-1,dy[y]);
    }
  }
  dijk(0,w*h);
  if(mn[gy*w+gx]==INF){
    cout << -1 << endl;
  }
  else cout << mn[gy*w+gx] << endl;
  return 0;
}