QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#537415#9156. 百万富翁Forested100 ✓2033ms102004kbC++173.8kb2024-08-30 13:11:002024-08-30 13:11:01

Judging History

你现在查看的是最新测评结果

  • [2024-08-30 13:11:01]
  • 评测
  • 测评结果:100
  • 用时:2033ms
  • 内存:102004kb
  • [2024-08-30 13:11:00]
  • 提交

answer

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

using i32 = int;
using i64 = long long;
template <typename T>
using V = vector<T>;
template <typename T>
using VV = V<V<T>>;
template <typename T>
using VVV = V<V<V<T>>>;

template <typename T>
bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T>
bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}

#define OVERRIDE4(a, b, c, d, ...) d
#define REP2(i, n) for (i32 i = 0; i < (i32)(n); ++i)
#define REP3(i, l, r) for (i32 i = (i32)(l); i < (i32)(r); ++i)
#define REP(...) OVERRIDE4(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
#define PER2(i, n) for (i32 i = (i32)(n)-1; i >= 0; --i)
#define PER3(i, l, r) for (i32 i = (i32)(r)-1; i >= (i32)(l); --i)
#define PER(...) OVERRIDE4(__VA_ARGS__, PER3, PER2)(__VA_ARGS__)
#define ALL(x) begin(x), end(x)
#define LEN(x) (i32) size(x)

void dbg(i32 x) { cerr << x; }
void dbg(i64 x) { cerr << x; }
template <typename T>
void dbg(V<T> arr) {
    cerr << '[';
    REP(i, LEN(arr)) {
        if (i) {
            cerr << ", ";
        }
        dbg(arr[i]);
    }
    cerr << ']';
}
void debug() { cerr << "\n"; }
template <typename Head, typename... Tail>
void debug(Head head, Tail... tail) {
    dbg(head);
    cerr << ", ";
    debug(tail...);
}

#ifdef DEBUGF
#define DBG(...)                       \
    do {                               \
        cerr << #__VA_ARGS__ << " : "; \
        debug(__VA_ARGS__);            \
    } while (false)
#else
#define DBG(...) (void)0
#endif

#include "richest.h"

V<i32> reduce(V<i32> st, i32 d, i32 m, i32 k) {
    V<i32> a, b;
    V<i32> sp;
    sp.push_back(0);
    REP(i, m) {
        i32 l = d * i, r = l + d;
        REP(j, l, r) REP(l, j + 1, r) {
            a.push_back(st[j]);
            b.push_back(st[l]);
        }
        sp.push_back(LEN(a));
    }
    REP(i, k) {
        i32 l = d * m + (d + 1) * i, r = l + d + 1;
        REP(j, l, r) REP(l, j + 1, r) {
            a.push_back(st[j]);
            b.push_back(st[l]);
        }
        sp.push_back(LEN(a));
    }
    V<i32> c = ask(a, b);
    V<i32> rem;
    REP(i, m) {
        i32 l = d * i, r = l + d;
        i32 ll = sp[i], rr = sp[i + 1];
        REP(j, l, r) {
            if (count(begin(c) + ll, begin(c) + rr, st[j]) == d - 1) {
                rem.push_back(st[j]);
            }
        }
    }
    REP(i, k) {
        i32 l = d * m + (d + 1) * i, r = l + d + 1;
        i32 ll = sp[m + i], rr = sp[m + i + 1];
        REP(j, l, r) {
            if (count(begin(c) + ll, begin(c) + rr, st[j]) == d) {
                rem.push_back(st[j]);
            }
        }
    }
    return rem;
}

i32 richest(i32 n, i32 t, i32 s) {
    if (t == 1) {
        V<i32> a, b;
        REP(i, n) REP(j, i + 1, n) {
            a.push_back(i);
            b.push_back(j);
        }
        V<i32> c = ask(a, b);
        VV<i32> gr(n, V<i32>(n, 1));
        REP(i, LEN(c)) {
            if (c[i] == a[i]) {
                gr[b[i]][a[i]] = 0;
            } else {
                gr[a[i]][b[i]] = 0;
            }
        }
        i32 ans = -1;
        REP(i, n) {
            if (count(ALL(gr[i]), 1) == n) {
                ans = i;
            }
        }
        return ans;
    }

    // V<i32> div({2, 2, 2, 2, 2, 3, 5, 15, 140});
    V<i32> rem(n);
    iota(ALL(rem), 0);
    rem = reduce(rem, 2, LEN(rem) / 2, 0);
    rem = reduce(rem, 2, LEN(rem) / 2, 0);
    rem = reduce(rem, 2, LEN(rem) / 2, 0);
    rem = reduce(rem, 2, LEN(rem) / 2, 0);
    rem = reduce(rem, 3, 20828, 4);
    rem = reduce(rem, 6, 3472, 0);
    rem = reduce(rem, 18, 5, 178);
    rem = reduce(rem, 183, 1, 0);
    return rem[0];
}

詳細信息


Pretests

Pretest #1:

score: 15
Accepted
time: 618ms
memory: 23520kb

input:

1000 1 499500 957319859

output:

Correct
7127326332295218295
1.000000
1331569654267968081

result:

points 1.0 Correct

Pretest #2:

score: 85
Accepted
time: 2016ms
memory: 101948kb

input:

1000000 20 2000000 29091473

output:

Correct Case 2, 85 / 85, maxt = 8, maxs = 1099944
7610580723948932399
1.000000
1331569654267968081

result:

points 1.0 Correct Case 2, 85 / 85, maxt = 8, maxs = 1099944


Final Tests

Test #1:

score: 15
Accepted
time: 625ms
memory: 24200kb

input:

1000 1 499500 957319857

output:

Correct
7127326332295218295
1.000000
1331569654267968081

result:

points 1.0 Correct

Test #2:

score: 85
Accepted
time: 2033ms
memory: 102004kb

input:

1000000 20 2000000 29091471

output:

Correct Case 2, 85 / 85, maxt = 8, maxs = 1099944
7610580723948932399
1.000000
1331569654267968081

result:

points 1.0 Correct Case 2, 85 / 85, maxt = 8, maxs = 1099944