結果

問題 No.5016 Worst Mayor
ユーザー assy1028assy1028
提出日時 2023-04-29 15:56:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 204 ms / 2,000 ms
コード長 6,638 bytes
コンパイル時間 1,816 ms
コンパイル使用メモリ 130,384 KB
実行使用メモリ 30,840 KB
スコア 12,507,518,158
平均クエリ数 400.00
最終ジャッジ日時 2023-04-29 15:56:18
合計ジャッジ時間 13,606 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 182 ms
30,140 KB
testcase_01 AC 168 ms
30,488 KB
testcase_02 AC 173 ms
30,144 KB
testcase_03 AC 164 ms
30,380 KB
testcase_04 AC 169 ms
29,904 KB
testcase_05 AC 181 ms
30,244 KB
testcase_06 AC 166 ms
30,612 KB
testcase_07 AC 186 ms
30,224 KB
testcase_08 AC 164 ms
30,084 KB
testcase_09 AC 165 ms
30,128 KB
testcase_10 AC 204 ms
30,196 KB
testcase_11 AC 154 ms
30,676 KB
testcase_12 AC 182 ms
30,256 KB
testcase_13 AC 160 ms
30,556 KB
testcase_14 AC 155 ms
30,116 KB
testcase_15 AC 153 ms
29,952 KB
testcase_16 AC 160 ms
30,156 KB
testcase_17 AC 159 ms
30,604 KB
testcase_18 AC 191 ms
30,416 KB
testcase_19 AC 182 ms
30,148 KB
testcase_20 AC 168 ms
30,764 KB
testcase_21 AC 164 ms
30,668 KB
testcase_22 AC 169 ms
30,172 KB
testcase_23 AC 169 ms
30,600 KB
testcase_24 AC 171 ms
30,464 KB
testcase_25 AC 164 ms
29,984 KB
testcase_26 AC 174 ms
30,212 KB
testcase_27 AC 156 ms
30,548 KB
testcase_28 AC 184 ms
30,424 KB
testcase_29 AC 173 ms
30,712 KB
testcase_30 AC 184 ms
30,664 KB
testcase_31 AC 161 ms
30,200 KB
testcase_32 AC 161 ms
30,060 KB
testcase_33 AC 148 ms
30,264 KB
testcase_34 AC 166 ms
30,324 KB
testcase_35 AC 166 ms
30,516 KB
testcase_36 AC 175 ms
30,588 KB
testcase_37 AC 168 ms
29,936 KB
testcase_38 AC 163 ms
30,560 KB
testcase_39 AC 167 ms
29,972 KB
testcase_40 AC 186 ms
30,552 KB
testcase_41 AC 163 ms
30,084 KB
testcase_42 AC 165 ms
30,116 KB
testcase_43 AC 194 ms
30,024 KB
testcase_44 AC 173 ms
30,124 KB
testcase_45 AC 157 ms
30,368 KB
testcase_46 AC 179 ms
30,472 KB
testcase_47 AC 175 ms
30,220 KB
testcase_48 AC 176 ms
30,084 KB
testcase_49 AC 169 ms
30,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
    size_t seed = hash<T>()(x.first);
    return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int INF = 1e9 + 9;
//const ll INF = 1e18 + 9;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const double EPS = 1e-8;
const double PI = acos(-1);

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

// [0, k)
int rand(int k) {
    return xor128() % k;
}

// [a, b)
int rand(int a, int b) {
    return a + xor128() % (b - a);
}

int n, t;
int a[3010], b[3010], c[3010], d[3010];
const int MAX_Y = 14;
const int MAX_X = 14;

double route_weight[15][15][2];
double weight_each[3010][15][15][2];
bool built[15][15][2];

struct road {
    double count;
    int x, y, t;
};
bool operator< (const road& r1, const road& r2) {
    return r1.count < r2.count;
}

vector<road> high_way;
bool prev_build = false;

void build(const road& r) {
    high_way.push_back(r);
    built[r.x][r.y][r.t] = true;
    prev_build = true;
    cout << "1 " << r.x+1 << " " << r.y+1 << " " << r.x+2-r.t << " " << r.y+r.t+1 << endl; cout.flush();
}

void get_coop() {
    prev_build = false;
    cout << "2" << endl; cout.flush();
}

void get_money() {
    prev_build = false;
    cout << "3" << endl; cout.flush();
}

bool in_area(const int idx, const road& r) {
    const int minY = min(a[idx], c[idx]);
    const int maxY = max(a[idx], c[idx]);
    const int minX = min(b[idx], d[idx]);
    const int maxX = max(b[idx], d[idx]);
    return minY <= r.x && r.x <= maxY && minY <= r.x+1-r.t && r.x+1-r.t <= maxY &&
           minX <= r.y && r.y <= maxX && minX <= r.y+r.t && r.y+r.t <= maxX;
}

void add_weight(const int idx) {
    const int minY = min(a[idx], c[idx]);
    const int maxY = max(a[idx], c[idx]);
    const int minX = min(b[idx], d[idx]);
    const int maxX = max(b[idx], d[idx]);
    for (int y = minY; y <= maxY; y++) {
        for (int x = minX; x <= maxX; x++) {
            route_weight[y][x][0] += weight_each[idx][y][x][0];
            route_weight[y][x][1] += weight_each[idx][y][x][1];
        }
    }
}

void subtract_weight(const int idx) {
    const int minY = min(a[idx], c[idx]);
    const int maxY = max(a[idx], c[idx]);
    const int minX = min(b[idx], d[idx]);
    const int maxX = max(b[idx], d[idx]);
    for (int y = minY; y <= maxY; y++) {
        for (int x = minX; x <= maxX; x++) {
            route_weight[y][x][0] -= weight_each[idx][y][x][0];
            route_weight[y][x][1] -= weight_each[idx][y][x][1];
        }
    }
}

void add_weight_each(const int idx, const int minY, const int maxY, const int minX, const int maxX, const double weight) {
    for (int y = minY; y <= maxY; y++) {
        for (int x = minX; x <= maxX; x++) {
            if (y < maxY) weight_each[idx][y][x][0] += weight;
            if (x < maxX) weight_each[idx][y][x][1] += weight;
        }
    }
}

void calc_weight_each(const int idx) {
    memset(weight_each[idx], 0, sizeof(weight_each[idx]));
    int cnt = 0;
    vector<road> h;
    for (const auto& r : high_way) {
        if (in_area(idx, r)) {
            cnt++;
            h.push_back(r);
        }
    }
    const double weight = cnt == 0 ? 1.0 : 1.0 / cnt;
    const int minY = min(a[idx], c[idx]);
    const int maxY = max(a[idx], c[idx]);
    const int minX = min(b[idx], d[idx]);
    const int maxX = max(b[idx], d[idx]);
    if (cnt == 0) {
        add_weight_each(idx, minY, maxY, minX, maxX, weight);
    } else if ((a[idx] - c[idx]) * (b[idx] - d[idx]) > 0){
        for (const auto& r : h) {
            add_weight_each(idx, minY, r.x, minX, r.y, weight);
            add_weight_each(idx, r.x+1-r.t, maxY, r.y+r.t, maxX, weight);
        }
    } else {
        for (const auto& r : h) {
            add_weight_each(idx, r.x+1-r.t, maxY, minX, r.y, weight);
            add_weight_each(idx, minY, r.x, r.y+r.t, maxX, weight);
        }
    }
}

void init() {
    for (int i = 0; i < n; i++) {
        calc_weight_each(i);
        add_weight(i);
    }
}

road get_candidate() {
    if (prev_build) {
        const auto& r = high_way.back();
        for (int i = 0; i < n; i++) {
            if (in_area(i, r)) {
                subtract_weight(i);
                calc_weight_each(i);
                add_weight(i);
            }
        }
    }
    
    double max_weight = 0;
    road ret;
    for (int y = 0; y < MAX_Y; y++) {
        for (int x = 0; x < MAX_X; x++) {
            if (y < MAX_Y-1 && !built[y][x][0] && route_weight[y][x][0] > max_weight) {
                ret = road{route_weight[y][x][0], y, x, 0};
                max_weight = route_weight[y][x][0];
            }
            if (x < MAX_X-1 && !built[y][x][1] && route_weight[y][x][1] > max_weight) {
                ret = road{route_weight[y][x][1], y, x, 1};
                max_weight = route_weight[y][x][1];
            }
        }
    }
    return ret;
}

void solve() {
    init();
    int u, v;
    for (int iter = 0; iter < t; iter++) {
        cin >> u >> v;
        const int cost = 1e7 / sqrt(v);
        const auto& r = get_candidate();
        const int gain = r.count * (t-iter) * 60 * pow(0.99, iter);
        //cerr << "??? " << u << " " << v << " " << cost << " " << gain << endl;
        if (gain >= cost && u >= cost) {
            build(r);
        } else if (iter < 150) {
            get_coop();
        } else {
            get_money();
        }
    }
}

void input() {
    cin >> n >> t;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
        c[i]--;
        d[i]--;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    solve();
}
0