/* ---------- 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];

const int trial = 7;

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));
    }

    sort(origin_iwashi.begin(), origin_iwashi.end());


    string best_cmd = "";
    int best_score = 0;

    for (int q = 0; q < trial; ++q) {
        auto iwashi = origin_iwashi;

        fill(iwashiMap[0], iwashiMap[22], 0);

        while (get<0>(iwashi[0]) == 0) {
            int x, y, t;
            tie(t, x, y) = iwashi[0];
            iwashiMap[y][x]++;
            iwashi.erase(iwashi.begin());
        }

        string cmd = "";
        int score = 0;
        int paralyzed = 0;
        for (int t = 1; t < T; t++) {
            int d = mert() % 4;
            for (int i = 0; i < 4; ++i, d = (d + 1) % 4) {
                int sx = px + dx[d];
                int sy = py + dy[d];

                if (0 <= sx && sx < 22 && 0 <= sy && sy < 22 && maps[sy][sx] != '#') {
                    cmd.push_back(dir[d]);
                    px = sx;
                    py = sy;
                    break;
                }
            }

            // iwashi move
            for (int i = 0; i < H; i++)
                for (int j = 0; j < W; j++)
                    nextIwashiMap[i][j] = 0;
            for (int i = 0; i < H; i++)
                for (int j = 0; j < W; j++) {
                    if (maps[i][j] == '#') continue;
                    if (nextIwashiMap[i][j] > 0) {
                        nextIwashiMap[i][j] += iwashiMap[i][j];
                        continue;
                    }
                    queue<pair<int, int>> q;
                    for (int y = 0; y < H; y++)
                        for (int x = 0; x < W; x++) {
                            if (maps[y][x] != '#' && iwashiMap[y][x] > 0 && !(y == i && x == j)) {
                                distanceMap[y][x] = 0;
                                q.push(make_pair(y, x));
                            } else
                                distanceMap[y][x] = W * H;
                        }
                    if (paralyzed == 0) {
                        distanceMap[py][px] = 0;
                        q.push(make_pair(py, px));
                    }
                    while (!q.empty()) {
                        int x = q.front().second, y = q.front().first;
                        q.pop();
                        for (int k = 0; k < 4; k++) {
                            int nx = x + dx[k];
                            int ny = y + dy[k];
                            if (maps[ny][nx] == '#') continue;
                            if (distanceMap[y][x] + 1 < distanceMap[ny][nx]) {
                                distanceMap[ny][nx] = distanceMap[y][x] + 1;
                                q.push(make_pair(ny, nx));
                            }
                        }
                    }
                    for (int k = 0; k < 5; k++) {
                        int ny = i + dy[k];
                        int nx = j + dx[k];
                        if (maps[ny][nx] == '#') continue;
                        if (distanceMap[i][j] > distanceMap[ny][nx] || k == 4) {
                            nextIwashiMap[ny][nx] += iwashiMap[i][j];
                            break;
                        }
                    }
                }
            for (int i = 0; i < H; i++)
                for (int j = 0; j < W; j++)
                    iwashiMap[i][j] = nextIwashiMap[i][j];

            // iwashi つちからはえてくるんだ
            while ((!iwashi.empty()) && get<0>(iwashi[0]) == t) {
                int x, y, hogeT;
                tie(hogeT, x, y) = iwashi[0];
                iwashiMap[y][x]++;
                iwashi.erase(iwashi.begin());
            }
            // scoreing
            if (paralyzed > 0) {
                paralyzed--;
            } else if (0 < iwashiMap[py][px] && iwashiMap[py][px] <= 5) {
                score += iwashiMap[py][px];
                iwashiMap[py][px] = 0;
            } else if (iwashiMap[py][px] > 5) {
                paralyzed += 5;
                iwashiMap[py][px] = 0;
            }
        }

        if (score > best_score) {
            best_score = score;
            best_cmd = cmd;
        }
    }
    cout << best_cmd << endl;
    return 0;
}

Battle History

ConfigScoreDate
10 x 10 tiny0.862018/11/24 16:34:40
20 x 20 little0.7842018/11/24 16:34:40
20 x 20 little0.2282018/11/24 16:34:40
20 x 20 little0.282018/11/24 16:34:40
20 x 20 little0.62018/11/24 16:34:40
20 x 20 little0.7082018/11/24 16:34:40
20 x 20 little0.4682018/11/24 16:34:40
20 x 20 much0.092666666672018/11/24 16:34:40
20 x 20 much0.12018/11/24 16:34:40
20 x 20 much0.0992018/11/24 16:34:40
20 x 20 much0.0782018/11/24 16:34:40
20 x 20 much0.088666666672018/11/24 16:34:40
20 x 20 much0.099666666672018/11/24 16:34:40
challenge0.1682018/11/24 16:34:40
challenge0.1652018/11/24 16:34:40
challenge0.1722018/11/24 16:34:40