QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#492914 | #9156. 百万富翁 | ningago | 100 ✓ | 3068ms | 142780kb | C++14 | 4.2kb | 2024-07-26 17:11:06 | 2024-07-26 17:11:08 |
Judging History
answer
#include "richest.h"
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <cctype>
#include <set>
namespace uvu
{
#define LOCAL ____________DONT_DEFINE_ME____________
#define ll long long
#define inf 0x3f3f3f3f
// #define int long long
// #define inf 0x3f3f3f3f3f3f3f3fll
#define infll 0x3f3f3f3f3f3f3f3fll
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define gline debug("now is #%d\n", __LINE__)
#define pii std::pair <int, int>
#define mkp std::make_pair
#define fi first
#define se second
char _ST_;
const int BUFSIZE = (1 << 20);
char ibuf[BUFSIZE], *iS = ibuf, *iT = ibuf;
char obuf[BUFSIZE], *oS = obuf, *oT = obuf + BUFSIZE;
char getc()
{
#ifdef LOCAL
return getchar();
#else
if(iS == iT) iT = (iS = ibuf) + fread(ibuf, 1, BUFSIZE, stdin);
return iS == iT ? EOF : *iS++;
#endif
#define getchar ERR
}
void Flush() { fwrite(obuf, 1, oS - obuf, stdout); oS = obuf; }
struct Flusher { ~Flusher(){ Flush(); } }iamflusher;
void putc(char c)
{
#ifdef LOCAL
putchar(c);
#else
*oS++ = c;
if(oS == oT) Flush();
#endif
#define putchar ERR
}
template <typename T = int> T read()
{
T x = 0, f = 1; char c = getc();
for(; !isdigit(c); c = getc()) if(c == '-') f = -1;
for(; isdigit(c); c = getc()) x = (x << 3) + (x << 1) + (c ^ 48);
return x * f;
}
template <typename T> void print(T x, char c)
{
static int sta[BUFSIZE], top;
top = 0;
if(x < 0) putc('-'), x = -x;
if(!x) sta[top = 1] = 0;
for(; x; x /= 10) sta[++top] = x % 10;
for(; top; ) putc(sta[top--] ^ 48);
if(c) putc(c);
}
int readstr(char *s, int base)
{
int idx = base - 1; char c = getc();
for(; !(isdigit(c) || isalpha(c) || c == '#' || c == '.'); c = getc());
for(; isdigit(c) || isalpha(c) || c == '#' || c == '.' ; c = getc()) s[++idx] = c;
return idx - base + 1;
}
void printf(const char *s) { for(; *s; s++) putc(*s); }
template <typename T, typename ... Args>
void printf(const char *s, T x, Args ... rest)
{
for(; *s; s++)
{
if(*s != '%') { putc(*s); continue; }
s++; if(*s == 'd') print(x, 0);
else if(*s == 'c') putc(x);
printf(s + 1, rest ...);
return;
}
}
template <typename T> void ckmax(T &x, T y) { x = x > y ? x : y; }
template <typename T> void ckmin(T &x, T y) { x = x < y ? x : y; }
#define mod 998244353
// #define mod 1000000007
int sm(int x) { return x >= mod ? x - mod : x; }
void plus_(int &x, int y) { x = sm(x + y); }
void mul_(int &x, int y) { x = 1ll * x * y % mod; }
int ksm(int a, int b) { int res = 1; for(; b; b >>= 1, mul_(a, a)) if(b & 1) mul_(res, a); return res; }
#define N 1000010
int n, f[9] = {500000, 250000, 125000, 62500, 20833, 3472, 183, 1};
std::vector <int> vec[N], now;
bool vis[N];
char _ED_;
int solve(int n, int T, int S)
{
debug("%.3f MB\n", abs(&_ST_ - &_ED_) / 1024.0 / 1024);
// memset(h, idx = -1, sizeof(h));
if(T == 20) T = 8;
else T = 1, f[0] = 1;
uvu::n = n; now.clear();
for(int i = 0; i < n; i++) now.push_back(i), vis[i] = 0;
for(int _ = 0; _ < T; _++)
{
int len = f[_], sc = 0;
// debug("len = %d (f[%d] = %d) sz = %d\n", len, _, f[_], (int)now.size());
// gline;
for(int t : now) { vec[sc].push_back(t); sc = (sc + 1) % len; }
// debug("sc = %d\n", sc);
// gline;
std::vector <int> a, b, c;
// gline;
for(int p = 0; p < len; p++)
{
int m = vec[p].size(); //if(m != 2) debug("%d ", m);
for(int i = 0; i < m; i++) for(int j = i + 1; j < m; j++) a.push_back(vec[p][i]), b.push_back(vec[p][j]);
}
// debug("\n");
// debug("query size = %d %d\n", (int)a.size(), (int)b.size());
// gline;
c = ask(a, b); int idx = 0;
// gline;
for(int p = 0; p < len; p++)
{
int m = vec[p].size();
for(int i = 0; i < m; i++) for(int j = i + 1; j < m; j++)
{
if(c[idx] == vec[p][i]) vis[vec[p][j]] = 1;
else vis[vec[p][i]] = 1;
idx++;
}
}
for(int i = 0; i < len; i++) vec[i].clear();
// gline;
std::vector <int> tmp;
// gline;
for(int t : now) if(!vis[t]) tmp.push_back(t);
std::swap(tmp, now);
// gline;
}
return now[0];
}
#undef N
#ifdef int
#undef int
#endif
}
int richest(int N, int T, int S) {
return uvu::solve(N, T, S);
}
详细
Pretests
Pretest #1:
score: 15
Accepted
time: 658ms
memory: 48592kb
input:
1000 1 499500 957319859
output:
Correct 7127326332295218295 1.000000 1331569654267968081
result:
points 1.0 Correct
Pretest #2:
score: 85
Accepted
time: 3068ms
memory: 142780kb
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: 626ms
memory: 50292kb
input:
1000 1 499500 957319857
output:
Correct 7127326332295218295 1.000000 1331569654267968081
result:
points 1.0 Correct
Test #2:
score: 85
Accepted
time: 3034ms
memory: 128308kb
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