QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#835462 | #9916. Defeat the Enemies | ucup-team2818# | WA | 2ms | 12040kb | C++14 | 4.1kb | 2024-12-28 11:58:29 | 2024-12-28 11:58:29 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <random>
#include <ctime>
#include <chrono>
#include <numeric>
#include <iomanip>
#include <cassert>
typedef long long ll;
typedef double lf;
typedef unsigned long long ull;
// #define DEBUG 1
struct IO
{
#define MAXSIZE (1 << 20)
#define isdigit(x) (x >= '0' && x <= '9')
char buf[MAXSIZE], *p1, *p2;
char pbuf[MAXSIZE], *pp;
#if DEBUG
#else
IO() : p1(buf), p2(buf), pp(pbuf) {}
~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
#endif
#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
#define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')
template <typename T>
void Read(T &x)
{
#if DEBUG
std::cin >> x;
#else
bool sign = 0; char ch = gc(); x = 0;
for (; !isdigit(ch); ch = gc())
if (ch == '-') sign = 1;
for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
if (sign) x = -x;
#endif
}
void Read(char *s)
{
#if DEBUG
std::cin >> s;
#else
char ch = gc();
for (; blank(ch); ch = gc());
for (; !blank(ch); ch = gc()) *s++ = ch;
*s = 0;
#endif
}
void Read(char &c) {for (c = gc(); blank(c); c = gc());}
void Push(const char &c)
{
#if DEBUG
putchar(c);
#else
if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
*pp++ = c;
#endif
}
template <typename T>
void Write(T x)
{
if (x < 0) x = -x, Push('-');
static T sta[35];
int top = 0;
do sta[top++] = x % 10, x /= 10; while (x);
while (top) Push(sta[--top] ^ 48);
}
template <typename T>
void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)
using namespace std;
const int MAXN = 2e4 + 210, MAXM = 5e5 + 10, mod = 998244353;
const ll INF = 1e18;
int n, m, K, c[110];
int hp[MAXM], amr[MAXM];
int a[MAXN], mxp[MAXN];
ll f[MAXN][110], g[MAXN][110];
int main()
{
#if DEBUG
#else
ios::sync_with_stdio(0), cin.tie(0);
#endif
int T;
Read(T);
while (T--)
{
Read(n), Read(m);
for (int i = 0; i <= m; i++) a[i] = 0;
for (int i = 1; i <= n; i++) Read(hp[i]);
for (int i = 1; i <= n; i++) Read(amr[i]), a[amr[i]] = max(a[amr[i]], hp[i]);
Read(K);
for (int i = 1; i <= K; i++) Read(c[i]);
int M = 2 * m + 2 * K;
for (int i = m + 1; i <= M; i++) a[i] = 0;
for (int i = M - 1; i >= 0; i--) a[i] = max(a[i], a[i + 1]);
for (int i = 1; i <= M; i++) mxp[i] = max(mxp[i - 1], a[i] + i);
for (int i = 0; i <= M; i++)
for (int j = 0; j <= K; j++)
f[i][j] = INF, g[i][j] = 0;
f[0][0] = 0, g[0][0] = 1;
for (int i = 0; i < M; i++)
for (int j = 0; j <= K; j++)
{
if (f[i][j] == INF) continue;
for (int k = i + 1; k <= M && k <= i + K; k++)
{
int t = max(mxp[i] + j, a[i + 1] + k) - mxp[k];
assert(t >= 0), assert(t <= K);
if (f[k][t] > f[i][j] + c[k - i]) f[k][t] = f[i][j] + c[k - i], g[k][t] = g[i][j];
else if (f[k][t] == f[i][j] + c[k - i]) g[k][t] = (g[k][t] + g[i][j]) % mod;
}
}
ll ans = INF, res = 0;
for (int i = m; i <= M; i++)
for (int j = 0; j <= K; j++)
{
if (mxp[i] + j > i) continue;
if (ans > f[i][j]) ans = f[i][j], res = g[i][j];
else if (ans == f[i][j]) res = (res + g[i][j]) % mod;
}
cout << ans << ' ' << (res % mod + mod) % mod << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 12040kb
input:
4 5 5 3 5 2 1 2 3 1 3 2 3 3 2 3 4 3 2 2 2 2 2 2 2 3 2 3 3 7 6 5 3 4 6 6 3 4 4 6 4 2 3 5 5 4 2 4 6 7 10 100 38 49 79 66 49 89 21 55 13 23 67 56 26 39 56 16 84 50 92 82 11 6 6 7 8 9 9 9 9 9 9 9
output:
9 1 6 4 18 18 99 44387
result:
ok 8 numbers
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 11920kb
input:
1000 5 3 1 1 3 1 2 3 2 1 1 2 1 5 5 3 3 3 2 2 1 1 1 3 1 1 3 3 1 3 5 5 4 3 5 1 4 5 5 2 5 5 2 1 5 5 5 5 5 5 5 4 2 1 2 4 1 2 1 1 5 3 2 1 2 1 1 1 3 2 1 1 1 5 2 1 1 1 1 1 3 2 2 1 5 5 2 3 5 2 2 5 2 4 3 1 2 3 3 5 1 1 1 1 1 1 1 1 1 1 1 3 5 4 4 5 4 1 4 4 4 2 4 3 1 3 3 1 2 1 5 2 2 3 4 2 4 1 5 4 5 1 4 2 5 1 5 1...
output:
20 1 3 1 9 1 5 4 20 1 2 1 15 4 8 4 14 1 6 3 36 1 12 1 27 1 2 1 20 1 4 1 10 1 23 1 10 1 4 1 28 1 4 1 5 1 4 1 6 1 8 1 6 1 16 1 9 6 5 1 30 1 4 1 4 1 3 1 35 1 10 1 2 1 4 1 15 6 4 1 20 1 4 1 6 1 40 1 4 1 18 1 8 1 7 1 6 1 2 1 10 1 3 1 9 1 8 1 4 1 6 4 20 1 8 1 10 1 2 1 2 1 50 1 24 1 6 1 10 16 10 1 6 1 3 1 ...
result:
wrong answer 19th numbers differ - expected: '4', found: '6'