QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#400931 | #6462. Jewel Thief | definieren | WA | 574ms | 18668kb | C++20 | 4.6kb | 2024-04-27 18:25:35 | 2024-04-27 18:25:36 |
Judging History
answer
#include <bits/stdc++.h>
#define fir first
#define sec second
#ifdef LOCAL
#define dbg(x) cerr << "In Line " << __LINE__ << " the " << #x << " = " << x << '\n';
#define dpi(x, y) cerr << "In Line " << __LINE__ << " the " << #x << " = " << x << " ; " << "the " << #y << " = " << y << '\n';
#define dbgf(fmt, args...) fprintf(stderr, fmt, ##args);
#else
#define dbg(x) void();
#define dpi(x, y) void();
#define dbgf(fmt, args...) void();
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using i128 = __int128_t;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using vi = vector<int>;
using vpii = vector<pii>;
bool Mbe;
constexpr int MOD = 998244353;
template<typename T> T add(T a, T b, T p = MOD) { return (a + b >= p) ? (a + b - p) : (a + b); }
template<typename T> T del(T a, T b, T p = MOD) { return (a - b < 0) ? (a - b + p) : (a - b); }
template<typename T> T mul(T a, T b, T p = MOD) { return 1ll * a * b % p; }
template<typename T> T cadd(T &a, T b, T p = MOD) { return a = add(a, b, p); }
template<typename T> T cdel(T &a, T b, T p = MOD) { return a = del(a, b, p); }
template<typename T> T cmul(T &a, T b, T p = MOD) { return a = mul(a, b, p); }
template<typename T> T cmax(T &a, T b) { return a = max(a, b); }
template<typename T> T cmin(T &a, T b) { return a = min(a, b); }
namespace FastIO {
constexpr int LEN = 1 << 20;
char in[LEN + 1], out[LEN + 1];
char *pin = in, *pout = out, *ein = in, *eout = out + LEN;
char gc() { return pin == ein && (ein = (pin = in) + fread(in, 1, LEN, stdin), ein == in) ? EOF : *pin ++; }
void pc(char c) { pout == eout && (fwrite(out, 1, LEN, stdout), pout = out); (*pout ++) = c; return; }
void Flush() { fwrite(out, 1, pout - out, stdout); pout = out; }
template<typename T> T Read() {
T x = 0; int f = 1; char ch = gc();
while (ch < '0' || ch > '9') f = (ch == '-' ? (~f + 1) : f), ch = gc();
while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gc();
return x * f;
}
template<typename T> void Write(T x, char c) {
static char stk[40]; int tp = 0;
if (x < 0) pc('-'), x = ~x + 1;
do stk[tp++] = x % 10 + 48, x /= 10; while (x);
while (tp --) pc(stk[tp]); pc(c); return;
}
void Read(char *s) {
char ch = gc();
while (!((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
(ch >= '0' && ch <= '9'))) ch = gc();
while ((ch != EOF) && ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
(ch >= '0' && ch <= '9'))) *s = ch, s ++, ch = gc();
*s = '\0'; return;
}
void Write(char *s) {
while (*s != '\0') pc(*s), s ++; return;
}
void Puts(char *s) {
Write(s), pc('\n'); return;
}
}
#define getchar FastIO::gc
#define putchar FastIO::pc
#define Flush FastIO::Flush
#define Read FastIO::Read
#define Write FastIO::Write
#define Puts FastIO::Puts
constexpr int MAXN = 1e6 + 5, MAXK = 1e5 + 5, MAXS = 3e2 + 5;
int n, m;
ll w[MAXN], f[2][MAXK];
vector<int> obj[MAXS], pos;
void slv() {
n = Read<int>(), m = Read<int>();
for (int i = 1; i <= n; i ++) {
int s = Read<int>(), v = Read<int>();
obj[s].emplace_back(v);
}
function<void(int, int, int, int, int)> solve =
[&](int o, int l, int r, int L, int R) {
if (l > r) return;
// if (L == R) {
// for (int i = l; i <= r; i ++)
// f[o][pos[i]] = f[o ^ 1][pos[L]] + w[i - L];
// return;
// }
int mid = l + r >> 1, opt = L;
ll ret = f[o ^ 1][pos[opt]] + w[mid - opt], tmp;
for (int j = L + 1, lim = min(mid, R); j <= lim; j ++)
if ((tmp = f[o ^ 1][pos[j]] + w[mid - j]) > ret) ret = tmp, opt = j;
f[o][pos[mid]] = ret;
solve(o, l, mid - 1, L, opt), solve(o, mid + 1, r, opt, R);
return;
};
int now = 0, pre = 1;
for (int i = 1; i <= 300; i ++) {
if (obj[i].empty()) continue;
swap(now, pre);
sort(obj[i].begin(), obj[i].end(), greater<int>());
for (int j = 1; j <= obj[i].size(); j ++)
w[j] = w[j - 1] + obj[i][j - 1];
for (int j = 0; j < i; j ++) {
pos.clear();
for (int k = j; k <= m; k += i)
pos.emplace_back(k);
solve(now, 0, pos.size() - 1, 0, pos.size() - 1);
}
for (int j = 1; j <= m; j ++)
cmax(f[now][j], f[now][j - 1]);
}
for (int i = 1; i <= m; i ++)
Write(f[now][i], ' ');
return;
}
void clr() {
return;
}
bool Med;
int main() {
#ifdef LOCAL
freopen("!in.in", "r", stdin);
freopen("!out.out", "w", stdout);
fprintf(stderr, "%.3lf Mb\n", fabs((&Mbe - &Med) / 1048576.0));
#endif
int T = 1;
// int T = Read<int>();
while (T --) slv(), clr();
Flush();
#ifdef LOCAL
fprintf(stderr, "%d ms\n", (int)clock());
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3564kb
input:
4 9 2 8 1 1 3 4 5 100
output:
1 8 9 9 100 101 108 109 109
result:
ok single line: '1 8 9 9 100 101 108 109 109 '
Test #2:
score: 0
Accepted
time: 1ms
memory: 3632kb
input:
5 7 2 2 3 8 2 7 2 4 3 8
output:
0 7 8 11 15 16 19
result:
ok single line: '0 7 8 11 15 16 19 '
Test #3:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
2 6 300 1 300 2
output:
0 0 0 0 0 0
result:
ok single line: '0 0 0 0 0 0 '
Test #4:
score: 0
Accepted
time: 26ms
memory: 18668kb
input:
1000000 100000 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59...
output:
1000000 1999999 2999997 3999994 4999990 5999985 6999979 7999972 8999964 9999955 10999945 11999934 12999922 13999909 14999895 15999880 16999864 17999847 18999829 19999810 20999790 21999769 22999747 23999724 24999700 25999675 26999649 27999622 28999594 29999565 30999535 31999504 32999472 33999439 3499...
result:
ok single line: '1000000 1999999 2999997 399999...249997 94999149999 95000050000 '
Test #5:
score: 0
Accepted
time: 500ms
memory: 12140kb
input:
1000000 100000 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 10 9 11 10 12 11 13 12 14 13 15 14 16 15 17 16 18 17 19 18 20 19 21 20 22 21 23 22 24 23 25 24 26 25 27 26 28 27 29 28 30 29 31 30 32 31 33 32 34 33 35 34 36 35 37 36 38 37 39 38 40 39 41 40 42 41 43 42 44 43 45 44 46 45 47 46 48 47 49 48 50 49 51 50 52...
output:
999900 1999500 2998800 3997800 4996500 5994900 6993000 7990800 8988300 9985500 10982400 11979000 12975300 13971300 14967000 15962400 16957500 17952300 18946800 19941000 20934900 21928500 22921800 23914800 24907500 25899900 26892000 27883800 28875300 29866500 30857400 31848000 32838300 33828300 34818...
result:
ok single line: '999900 1999500 2998800 3997800...391158 14095465559 14095540259 '
Test #6:
score: -100
Wrong Answer
time: 574ms
memory: 12648kb
input:
1000000 100000 215 147097103 134 678126202 99 584874219 117 706686049 115 916008673 30 162264571 258 432473996 198 594445641 220 297145909 65 930644070 244 407860992 142 29223115 88 672186982 159 425618716 135 940015882 157 487536108 231 274342869 186 476447051 218 224412395 246 190206170 40 9447381...
output:
999806703 1999387329 2998933273 3997600596 4996253636 5994813962 6993341251 7991739112 8990090915 9988030031 10985967744 11983790477 12981604791 13979203678 14976661166 15973082139 16969021626 17964792681 18960320420 19955515110 20950479371 21945397018 22939871008 23934321385 24928593459 25922728871...
result:
wrong answer 1st lines differ - expected: '999806703 1999387329 299893327...6 14030752721202 14030826574137', found: '999806703 1999387329 299893327... 14071906279689 14071980625005 '