#include #define MAXN 200005 #define MAXK 55 #define INF 1000000000 using namespace std; int n, k, s, w, z, x, y; int scoreSize = 0; int score[MAXN]; pair blackHoles[MAXN]; int changeTime = 0; pair dirs[4] = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}}; map, bool> visited; int get_size(int p) { return int(1.0 * (p - 1) * 1.0 * sqrt(2)); } void Read() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k >> s >> w >> z >> x >> y; scoreSize = get_size(n); for (int i = 0; i <= scoreSize; i++) cin >> score[i]; for (int i = 1; i <= k; i++) cin >> blackHoles[i].first >> blackHoles[i].second; } void Change() { for (int i = 1; i <= k; i++) { blackHoles[i].first = ((1LL * blackHoles[i].first * w + 1LL * z)) % (n + 1); blackHoles[i].second = ((1LL * blackHoles[i].second * z + 1LL * w)) % (n + 1); } } int get_dist(int x1, int y1, int x2, int y2) { return int(sqrt(1LL * (x1 - x2) * 1LL * (x1 - x2) + 1LL * (y1 - y2) * 1LL * (y1 - y2))); } int distToClosestBH(int currX, int currY) { int minDist = INF; for (int i = 1; i <= k; i++) { minDist = min(minDist, get_dist(currX, currY, blackHoles[i].first, blackHoles[i].second)); } return score[minDist]; } void printDirection(int d) { if (d == 0) cout << "L"; if (d == 1) cout << "U"; if (d == 2) cout << "R"; if (d == 3) cout << "D"; } bool isBlackHole(int currX, int currY) { for (int i = 1; i <= k; i++) { if (blackHoles[i] == make_pair(currX, currY)) return true; } return false; } void Solve() { changeTime = int(1.0 * sqrt(s)); pair currPos = {x, y}; for (int i = 0; i <= s; i++) { if (i > 0 && i % changeTime == 0) Change(); int bestDir = 0; int result = 0; for (int d = 0; d < 4; d++) { int nextX = currPos.first + dirs[d].first; int nextY = currPos.second + dirs[d].second; if (nextX < 1 || nextX > n || nextY < 1 || nextY > n) continue; if (visited.find({nextX, nextY}) != visited.end()) continue; //if (isBlackHole(nextX, nextY)) continue; int currScore = distToClosestBH(nextX, nextY); if (result < currScore) { result = currScore; bestDir = d; } } int nextX = currPos.first + dirs[bestDir].first; int nextY = currPos.second + dirs[bestDir].second; if (nextX >= 1 && nextX <= n && nextY >= 1 && nextY <= n) { currPos = {currPos.first + dirs[bestDir].first, currPos.second + dirs[bestDir].second}; visited[currPos] = true; } else { for (int d = 0; d < 4; d++) { nextX = currPos.first + dirs[d].first; nextY = currPos.second + dirs[d].second; if (nextX >= 1 && nextX <= n && nextY >= 1 && nextY <= n) { bestDir = d; currPos = {nextX, nextY}; visited[currPos] = true; break; } } } if (i < s) printDirection(bestDir); } cout << endl; } int main() { freopen("cleanUp.in", "r", stdin); freopen("cleanUp.out", "w", stdout); Read(); Solve(); return 0; }