結果

問題 No.5016 Worst Mayor
ユーザー tempura_pptempura_pp
提出日時 2023-04-29 16:51:34
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 5,198 bytes
コンパイル時間 2,924 ms
コンパイル使用メモリ 156,656 KB
実行使用メモリ 41,500 KB
スコア 15,887,442,614
最終ジャッジ日時 2023-04-29 16:54:14
合計ジャッジ時間 106,253 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,978 ms
40,872 KB
testcase_01 AC 1,934 ms
40,836 KB
testcase_02 AC 1,918 ms
40,604 KB
testcase_03 AC 1,922 ms
41,060 KB
testcase_04 AC 1,958 ms
40,860 KB
testcase_05 AC 1,973 ms
40,744 KB
testcase_06 AC 1,944 ms
41,344 KB
testcase_07 AC 1,957 ms
40,964 KB
testcase_08 AC 1,974 ms
41,204 KB
testcase_09 AC 1,979 ms
40,792 KB
testcase_10 AC 1,951 ms
41,228 KB
testcase_11 AC 1,978 ms
40,656 KB
testcase_12 AC 1,963 ms
40,736 KB
testcase_13 AC 1,991 ms
40,712 KB
testcase_14 AC 1,987 ms
40,904 KB
testcase_15 AC 1,917 ms
40,524 KB
testcase_16 AC 1,971 ms
41,180 KB
testcase_17 TLE -
testcase_18 AC 1,980 ms
40,912 KB
testcase_19 AC 1,941 ms
40,796 KB
testcase_20 TLE -
testcase_21 AC 1,955 ms
41,500 KB
testcase_22 AC 1,982 ms
41,404 KB
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 AC 1,986 ms
40,772 KB
testcase_27 AC 1,960 ms
41,200 KB
testcase_28 TLE -
testcase_29 AC 1,981 ms
40,276 KB
testcase_30 AC 1,974 ms
40,440 KB
testcase_31 AC 1,955 ms
40,932 KB
testcase_32 TLE -
testcase_33 AC 1,957 ms
40,496 KB
testcase_34 AC 1,993 ms
41,244 KB
testcase_35 AC 1,994 ms
40,808 KB
testcase_36 AC 1,962 ms
40,704 KB
testcase_37 TLE -
testcase_38 TLE -
testcase_39 TLE -
testcase_40 AC 1,953 ms
40,788 KB
testcase_41 AC 1,965 ms
40,416 KB
testcase_42 AC 1,960 ms
41,112 KB
testcase_43 AC 1,974 ms
40,976 KB
testcase_44 AC 1,978 ms
41,080 KB
testcase_45 TLE -
testcase_46 TLE -
testcase_47 AC 1,952 ms
41,448 KB
testcase_48 AC 1,993 ms
41,028 KB
testcase_49 AC 1,932 ms
40,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
constexpr int inf = 1e9 + 7;
constexpr ll longinf = 1LL << 60;
constexpr ll mod = 1e9 + 7;

struct Xor128 {
    unsigned x, y, z, w;

    Xor128(unsigned w_ = 88675123) : x(123456789), y(362436069), z(521288629), w(w_){};

    inline unsigned xor128() {
        unsigned t;
        t = x ^ (x << 11);
        x = y;
        y = z;
        z = w;
        return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
    }

    int nextInt(int x, int y) {
        if(x > y)
            swap(x, y);
        return xor128() % (y - x) + x;
    }

    double nextDouble(double a, double b) {
        return (double)(xor128() & 0xffff) / 0xffff * (b - a) + a;
    }
};

int dist[200][200];
int N = 3000, T = 400, M = 196;
int cost[3030];
int s[3030], t[3030];
int NC = 100000, NH = 22301;

void input() {
    int _;
    cin >> _ >> _;
    rep(i, N) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        --a;
        --b;
        --c;
        --d;
        s[i] = a * 14 + b;
        t[i] = c * 14 + d;
    }
}

pair<int, int> etov(int e) {
    int x, y;
    if(e < 13 * 14) {
        x = (e / 13) * 14 + e % 13;
        y = x + 1;
    } else {
        e -= 13 * 14;
        x = e;
        y = e + 14;
    }
    return {x, y};
}

struct State {
    int score;
    int dist[196][196];
    vector<int> result;
    vector<int> up;
    State() : result(0), score(0), up(0) {
        rep(i, 196) rep(j, 196) {
            dist[i][j] = NC * 50;
        }
        rep(i, 14) rep(j, 14) {
            int x = i * 14 + j;
            if(j > 0) {
                dist[x][x - 1] = NC;
            }
            if(j < 13) {
                dist[x][x + 1] = NC;
            }
            if(i > 0) {
                dist[x][x - 14] = NC;
            }
            if(i < 13) {
                dist[x][x + 14] = NC;
            }
            dist[x][x] = 0;
        }
        rep(i, M) rep(j, M) rep(k, M) {
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
        }
    }
    static State getNewState(State &s, int e, int score) {
        s.result.push_back(e);
        s.up.push_back(score - s.score);
        auto [v1, v2] = etov(e);
        s.dist[v1][v2] = NH;
        s.dist[v2][v1] = NH;
        rep(i, M) rep(j, M) {
            s.dist[i][j] = min(s.dist[i][j], min(s.dist[i][v1] + s.dist[v2][j] + NH, s.dist[i][v2] + s.dist[v1][j] + NH));
        }
        s.score = score;
        return s;
    }
    int getNextScore(int e) {
        int res = 0;
        auto [v1, v2] = etov(e);
        rep(i, N) {
            int nc = min(dist[s[i]][t[i]], min(dist[s[i]][v1] + dist[v2][t[i]] + NH, dist[s[i]][v2] + dist[v1][t[i]] + NH));
            res += nc % 100;
        }
        return res + score;
    }
};

auto rng = Xor128();
State search() {
    State s;
    vector<State> bests;
    bests.emplace_back(s);
    rep(i, 90) {
        int t = i == 0 ? 400 : 40;
        priority_queue<pair<int, pair<int, int>>> pq;
        rep(c, bests.size()) {
            rep(_, t) {
                int e = rng.nextInt(0, 2 * 14 * 13);
                int ns = bests[c].getNextScore(e);
                pq.push({ns, {-c, e}});
            }
        }
        vector<State> nb;
        rep(_, 30) {
            auto p = pq.top();
            pq.pop();
            int s = p.first, id = -p.second.first, e = p.second.second;
            State state = bests[id];
            auto ns = State::getNewState(state, e, s);
            nb.emplace_back(ns);
        }
        nb.swap(bests);
    }
    return bests[0];
}

int num = 0;
void output(int e) {
    auto [x, y] = etov(e);
    cout << 1 << " ";
    cout << x / 14 + 1 << " " << x % 14 + 1 << " ";
    cout << y / 14 + 1 << " " << y % 14 + 1 << endl;
}

int cur = 0;
int U = 1000000, V = 1;
pair<int, int> read() {
    // cerr << cur << " " << U << " " << V << endl;
    // return {U, V};
    int u, v;
    cin >> u >> v;
    return {u, v};
}

void turn(int t, State &state) {
    auto p = read();
    int u = p.first, v = p.second;
    int ma = num < 90 ? state.up[num] : cur;
    int ben = 60 * (ma - cur) * (T - t);
    int pay = (int)(10000000 / sqrt(v));
    cerr << ben << " " << pay << endl;
    if((ben > pay || num < 75) && u > pay) {
        output(state.result[num]);
        ++num;
        U = u - pay;
        cur = ma;
    } else {
        int npay = (int)(10000000 / sqrt(v + 1));
        int dpay = max(0, min(90 - num, T - t - 1)) * (pay - npay);
        if(dpay > 50000) {
            cout << 2 << endl;
            V = v + 1;
        } else {
            cout << 3 << endl;
            U = u + 50000;
        }
    }
    U += cur * 60;
}

int main() {
    input();
    State state = search();
    rep(i, T) {
        turn(i, state);
    }
    cerr << U << " " << V << endl;
    cerr << num << endl;
    return 0;
}
0