結果

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

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 WA 0% 16ms 0KB
2 WA 0% 14ms 0KB
3 WA 0% 21ms 0KB
4 WA 0% 20ms 0KB
5 WA 0% 21ms 0KB
6 WA 0% 20ms 0KB
7 AC 100% 6ms 17280KB
8 WA 0% 34ms 0KB
9 WA 0% 21ms 0KB
10 WA 0% 30ms 0KB
11 WA 0% 18ms 0KB
12 AC 100% 22ms 25712KB
13 WA 0% 23ms 0KB
14 WA 0% 21ms 0KB
15 WA 0% 19ms 0KB
16 AC 100% 13ms 21360KB
17 WA 0% 19ms 0KB
18 WA 0% 19ms 0KB
19 WA 0% 16ms 0KB
20 AC 100% 10ms 20080KB

ソースコード

#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 100000
#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;
}