Submission #2084055


Source Code Expand

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define int long long

int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int H, W, K, sr, sc;
int s[50][50] = {};
int d[50][50] = {};
bitset<50> visited[50] = {};
char ans[4] = {'R', 'D', 'L', 'U'};

unsigned randxor() {
    static unsigned x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned t;
    t = x ^ (x << 11);
    x = y;
    y = z;
    z = w;
    return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}

int rand_dist(int max) {
    return randxor() % max;
}

void sqcpy(bitset<50> parent[50], bitset<50> child[50]) {
    for (int i = 0; i < 50; i++) {
        child[i] = parent[i];
    }
}

int evaluate(bitset<50> vsd[50], int turn, int x, int y) {
    int res = 0;
    for (int i = turn; i < min(turn + 40, K); i++) {
        if (!vsd[y][x]) {
            res += s[y][x] - i * d[y][x];
            vsd[y].set(x);
        }
        vector<int> way;
        for (int j = 0; j < 4; j++) {
            if (s[y + dy[j]][x + dx[j]] != -1) {
                way.push_back(j);
            }
        }
        int det = rand_dist(way.size());
        x += dx[way[det]], y += dy[way[det]];
    }
    return res;
}

int determine_hand(bitset<50> vsd[50], int turn, int x, int y) {
    int hand;
    int max_score = LLONG_MIN;
    vector<int> way;
    for (int i = 0; i < 4; i++) {
        if (s[y + dy[i]][x + dx[i]] == -1) {
            continue;
        }
        way.push_back(i);
        int cur_score = 0;
        for (int j = 0; j < 200; j++) {
            bitset<50> vsd_cpy[50];
            sqcpy(vsd, vsd_cpy);
            cur_score += evaluate(vsd_cpy, turn, x + dx[i], y + dy[i]);
        }
        if (cur_score > max_score) {
            max_score = cur_score;
            hand = i;
        }
    }
    return hand;
}

signed main() {
    cin >> H >> W >> K >> sr >> sc;
    for (int i = 0; i < 50; i++) {
        string a;
        cin >> a;
        for (int j = 0; j < 50; j++) {
            if (a[j] == '#') {
                s[i][j] = -1;
            }
        }
    }
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int fr, fc, F, D;
        cin >> fr >> fc >> F >> D;
        s[fr - 1][fc - 1] = F;
        d[fr - 1][fc - 1] = D;
    }
    sr--, sc--;
    for (int i = 0; i < K; i++) {
        int hand = determine_hand(visited, i, sc, sr);
        cout << ans[hand];
        sc += dx[hand], sr += dy[hand];
        visited[sr].set(sc);
    }
    cout << endl;
    return 0;
}

Submission Info

Submission Time
Task B - Food Collector
User packer_jp
Language C++14 (GCC 5.4.1)
Score 15590
Code Size 2636 Byte
Status AC
Exec Time 8299 ms
Memory 256 KB

Judge Result

Set Name test_01 test_02 test_03 test_04 test_05 test_06 test_07 test_08 test_09 test_10
Score / Max Score 1660 / 20000 2289 / 20000 1671 / 20000 964 / 20000 1403 / 20000 1981 / 20000 1545 / 20000 1396 / 20000 898 / 20000 1783 / 20000
Status
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
Set Name Test Cases
test_01 subtask_01_01.txt
test_02 subtask_01_02.txt
test_03 subtask_01_03.txt
test_04 subtask_01_04.txt
test_05 subtask_01_05.txt
test_06 subtask_01_06.txt
test_07 subtask_01_07.txt
test_08 subtask_01_08.txt
test_09 subtask_01_09.txt
test_10 subtask_01_10.txt
Case Name Status Exec Time Memory
subtask_01_01.txt AC 5983 ms 256 KB
subtask_01_02.txt AC 7170 ms 256 KB
subtask_01_03.txt AC 7179 ms 256 KB
subtask_01_04.txt AC 8299 ms 256 KB
subtask_01_05.txt AC 4805 ms 256 KB
subtask_01_06.txt AC 7025 ms 256 KB
subtask_01_07.txt AC 7706 ms 256 KB
subtask_01_08.txt AC 4556 ms 256 KB
subtask_01_09.txt AC 4051 ms 256 KB
subtask_01_10.txt AC 6422 ms 256 KB