/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */

using namespace std;

/* ---------- Type Abbreviation ---------- */

using ll = long long;

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

#define mp make_pair
#define mt make_tuple

/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)

/* ---------- container ---------- */

#define gsort(b, e) sort(b, e, greater<decltype(*b)>())

/* ----------- debug ---------- */

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "(" << p.first << "," << p.second << ")";
}

/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */

template <typename T>
inline T sq(T a) { return a * a; }

template <typename T>
T gcd(T a, T b) {
    if (a > b) return gcd(b, a);
    return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b /* % MOD */;
    if (n % 2 == 0) {
        return mypow(b * b /* % MOD */, n / 2);
    } else {
        return mypow(b, n - 1) * b /* % MOD */;
    }
}

ll pcnt(ll b) {
    return __builtin_popcountll(b);
}

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

const int dx[] = {1, 0, -1, 0, 0};
const int dy[] = {0, 1, 0, -1, 0};
const string dir = "ESWNX";

int H, W, T, N;
string maps[22];
vector<tuple<int, int, int>> origin_iwashi;
int iwashiMap[23][22];
int nextIwashiMap[22][22];
int distanceMap[22][22];

int main() {
    cin >> H >> W >> T >> N;
    int px, py;
    cin >> px >> py;
    px--;
    py--;
    for (int i = 0; i < H; i++)
        cin >> maps[i];
    for (int i = 0; i < N; i++) {
        int x, y, t;
        cin >> x >> y >> t;
        y--;
        x--;
        origin_iwashi.push_back(make_tuple(t, x, y));
    }

    int rev[H][W];
    int dis[H][W];
    fill(rev[0], rev[H], -1);
    fill(dis[0], dis[H], INF);

    queue<pair<int, int>> que;
    que.push(make_pair(px, py));

    while (!que.empty()) {
        int x, y;
        tie(x, y) = que.front();
        que.pop();

        for (int d = 0; d < 4; ++d) {
            int nx = x + dx[d], ny = y + dy[d];
            if (nx < 0 || W <= nx || ny < 0 || H <= ny || maps[ny][nx] == '#' || rev[ny][nx] != -1) continue;
            dis[ny][nx] = dis[y][x] + 1;
            rev[ny][nx] = d;
        }
    }

    int to_x = 0, to_y = 0;
    for (int x = 0; x < W; ++x) {
        for (int y = 0; y < H; ++y) {
            if (maps[y][x] == '#' || dis[y][x] == INF) continue;
            if (abs(x - W / 2) + abs(y - H / 2) < abs(to_x - W / 2) + abs(to_y - H / 2)) {
                to_x = x;
                to_y = y;
                continue;
            }
        }
    }

    cout << mp(to_x, to_y) << endl;
    cout << rev[to_y][to_x] << endl;

    string cmd;
    while (rev[to_y][to_x] >= 0) {
        int d = rev[to_y][to_x];
        cmd.insert(0, 1, dir[d]);
        to_x -= dx[d];
        to_y -= dy[d];
    }

    cout << cmd << endl;
    return 0;
}

Battle History

ConfigScoreDate
10 x 10 tiny0.662018/11/24 17:05:41
20 x 20 little0.9242018/11/24 17:05:41
20 x 20 little0.3762018/11/24 17:05:41
20 x 20 little0.6042018/11/24 17:05:41
20 x 20 little0.1882018/11/24 17:05:41
20 x 20 little0.5682018/11/24 17:05:41
20 x 20 little0.262018/11/24 17:05:41
20 x 20 much0.0882018/11/24 17:05:41
20 x 20 much0.12166666672018/11/24 17:05:41
20 x 20 much0.1272018/11/24 17:05:41
20 x 20 much0.10133333332018/11/24 17:05:41
20 x 20 much0.12018/11/24 17:05:41
20 x 20 much0.062333333332018/11/24 17:05:41
challenge0.1982018/11/24 17:05:41
challenge0.1732018/11/24 17:05:41
challenge0.1662018/11/24 17:05:41