結果

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

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 AC 100% 21ms 10320KB
2 WA 0% 20ms 9584KB
3 WA 0% 60ms 15696KB
4 WA 0% 58ms 18816KB
5 AC 100% 26ms 10640KB
6 AC 100% 97ms 28592KB
7 AC 100% 3ms 7696KB
8 WA 0% 72ms 13808KB
9 AC 100% 50ms 12752KB
10 AC 100% 37ms 13808KB
11 WA 0% 38ms 12992KB
12 AC 100% 10ms 8336KB
13 WA 0% 10ms 0KB
14 AC 100% 19ms 9584KB
15 AC 100% 160ms 31856KB
16 WA 0% 6ms 7952KB
17 WA 0% 37ms 13968KB
18 AC 100% 42ms 12752KB
19 WA 0% 9ms 0KB
20 AC 100% 4ms 7424KB

ソースコード

#include <bits/stdc++.h>

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second

int dxy[5] = {0, 1, 0, -1, 0};
// assign avl ncm dijkstra geo2 kruskal graph uf lca BIT
// matrix dinic next_combination topcoder

signed main()
{
    int2(h, w);
    int2(x, y);

    vvi board(h+1, vi(w+1, INF));
    vi mx(h), my(w);
    rep(i, h) {
        cin >> mx[i];
    }
    rep(i, w) {
        cin >> my[i];
    }
    h++; w++;
    int2(sx, sy);
    int2(gx, gy);
    //std::cout << "no" << std::endl;
    for (int i = sx; i <= gx; i++) {
        for (int j = sy; j <= gy; j++) {
            board[i][j] = -1;
        }
    }

    board[1][1] = 0;
    queue<pair <int, i_i> > Funami;
    Funami.push(mp(0, i_i(1, 1)));
    while (!Funami.empty()) {
        int cost = Funami.front().fir;
        int nx = Funami.front().sfir, ny = Funami.front().ssec;
        Funami.pop();
//        std::cout << nx << " " << ny << std::endl;
        if (board[nx][ny] == cost) {
            rep(i, 4) {
                int nnx = nx + dxy[i], nny = ny + dxy[i+1];
                if (0 < nnx && nnx < h && 0 < nny && nny < w) {
                    if (!i || i == 2) {
                        if (board[nnx][nny] > cost + mx[nnx-1]) {
                            int tmp = cost + mx[nnx-1];
                            board[nnx][nny] = tmp;
                            Funami.push(mp(tmp, i_i(nnx, nny)));
                        }
                    } else {
                        if (board[nnx][nny] > cost + my[nny-1]) {
                            int tmp = cost + my[nny-1];
                            board[nnx][nny] = tmp;
                            Funami.push(mp(tmp, i_i(nnx, nny)));
                        }
                    }
                }
            }
        }
    }

    /*
    rep(i, h) {
        rep(j, w) {
            std::cout << board[i][j] << " ";
        } cout << endl;
    }
    */


    if (board[x][y] == INF) {
        std::cout << -1 << std::endl;
    } else {
        std::cout << board[x][y] << std::endl;
    }

    return 0;
}