結果

提出番号 962
提出者 tsutaj
言語 C++
提出日時 2017-08-01 16:31:17
問題名 (44)玉ねぎの収穫をするkotamanegi
結果 WA
点数 0%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 AC 100% 26ms 19648KB
2 WA 0% 4ms 12912KB
3 WA 0% 104ms 26656KB
4 WA 0% 61ms 35808KB
5 AC 100% 47ms 19744KB
6 AC 100% 28ms 39856KB
7 AC 100% 3ms 8320KB
8 WA 0% 79ms 23072KB
9 AC 100% 37ms 30112KB
10 AC 100% 17ms 22880KB
11 WA 0% 43ms 22640KB
12 AC 100% 8ms 18624KB
13 WA 0% 38ms 21312KB
14 AC 100% 5ms 18016KB
15 AC 100% 158ms 46992KB
16 WA 0% 3ms 9296KB
17 WA 0% 50ms 25536KB
18 AC 100% 43ms 30384KB
19 WA 0% 19ms 18448KB
20 AC 100% 4ms 11328KB

ソースコード

// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int wx[] = {1, 1, 0, 0};
int wy[] = {0, 0, 1, 1};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int H, W;
int dist[1010][1010];
int gx, gy;
int X[1010], Y[1010];
int lx, ly, rx, ry;

struct Elem {
    int x, y, cost;
};
bool operator<(const Elem &a, const Elem &b) {
    return a.cost > b.cost;
}

signed main() {
    cin >> H >> W >> gx >> gy; gx--; gy--;
    rep(i,0,H) cin >> X[i];
    rep(i,0,W) cin >> Y[i];
    cin >> lx >> ly >> rx >> ry;
    lx--; ly--; rx--; ry--;

    rep(i,0,H) rep(j,0,W) dist[i][j] = INF;
    dist[0][0] = 0;

    priority_queue<Elem> q;
    q.push(Elem{0, 0, 0});
    while(!q.empty()) {
        Elem t = q.top(); q.pop();
        int x = t.x, y = t.y, c = t.cost;
        if(x == gx && y == gy) break;
        rep(i,0,4) {
            int nx = x + dx[i], ny = y + dy[i];
            if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if(lx <= nx && nx <= rx && ly <= ny && ny <= ry) continue;
            int edge = X[x] * wx[i] + Y[y] * wy[i];
            if(dist[nx][ny] > dist[x][y] + edge) {
                dist[nx][ny] = dist[x][y] + edge;
                q.push(Elem{nx, ny, dist[nx][ny]});
            }
        }
    }
    cout << dist[gx][gy] << endl;
    return 0;
}