QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#535957 | #9220. Bus Analysis | Max_s_xaM | WA | 943ms | 12300kb | C++17 | 4.4kb | 2024-08-28 17:01:48 | 2024-08-28 17:01:50 |
Judging History
answer
#include <iostream>
typedef long long ll;
typedef double lf;
// #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 = 1010, mod = 1e9 + 7;
inline int adu(int x, int y) { return (x += y) >= mod ? x - mod : x; }
inline void add(int &x, int y) { (x += y) >= mod && (x -= mod); }
int n;
int a[MAXN];
struct value
{
int x, y;
value operator + (const value &u) const { return value{adu(x, u.x), adu(y, u.y)}; }
void operator += (const value &u) { add(x, u.x), add(y, u.y); }
value operator * (const int &u) const { return value{(int)((x + (ll)y * u) % mod), y}; }
}f[2][MAXN][21][21], g[2][MAXN], ans;
inline void Clear(int p)
{
for (int i = 0; i <= n; i++)
for (int j = 0; j <= 20; j++)
for (int k = 0; k <= 20; k++)
f[p][i][j][k] = {0, 0};
for (int i = 0; i <= n; i++)
g[p][i] = {0, 0};
}
int main()
{
#if DEBUG
#else
ios::sync_with_stdio(0), cin.tie(0);
#endif
Read(n);
for (int i = 1; i <= n; i++) Read(a[i]);
a[0] = -2e9;
bool p = 0;
g[p][0].y = 1;
for (int i = 1; i <= n; i++)
{
Clear(!p);
for (int j = 0; j <= n; j++)
if (g[p][j].y)
{
g[!p][j] += g[p][j];
if (a[j] + 75 > a[i]) g[!p][j] += g[p][j];
else f[!p][i][0][0] += g[p][j];
}
for (int j = 0, x, y; j <= i; j++)
for (int u = 0; u <= 20; u++)
for (int v = 0; v <= 20; v++)
if (f[p][j][u][v].y)
{
f[!p][j][u][v] += f[p][j][u][v];
if (!u)
{
if (a[j] + 20 > a[i]) f[!p][j][0][0] += f[p][j][0][0];
else f[!p][j][i - j][0] += f[p][j][0][0];
}
else if (!v)
{
if (a[j + u] + 20 > a[i]) f[!p][j][u][0] += f[p][j][u][0];
else f[!p][j][u][i - j - u] += f[p][j][u][0];
}
else if (a[j + u + v] + 20 > a[i]) f[!p][j][u][v] += f[p][j][u][v];
else if (a[j] + 75 > a[i]) g[!p][j] += f[p][j][u][v] * 3;
else f[!p][j + u][v][i - j - u - v] += f[p][j][u][v] * 1;
}
p = !p;
}
for (int i = 0; i <= n; i++)
for (int j = 0; j <= 20; j++)
for (int k = 0; k <= 20; k++)
ans += f[p][i][j][k] * (1 + (j != 0) + (k != 0));
for (int i = 0; i <= n; i++)
ans += g[p][i];
cout << ans.x * 2ll % mod << "\n";
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7772kb
input:
3 1 8 20
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: 0
Accepted
time: 1ms
memory: 7716kb
input:
5 25 45 65 85 1000000000
output:
156
result:
ok 1 number(s): "156"
Test #3:
score: -100
Wrong Answer
time: 943ms
memory: 12300kb
input:
1000 2 7 9 12 14 17 18 21 22 28 29 33 34 35 37 38 44 45 46 50 58 59 63 66 71 72 75 76 77 78 80 81 83 84 87 92 100 101 107 108 109 112 114 116 118 123 124 131 142 143 144 145 148 150 151 152 153 155 157 158 165 167 168 169 171 176 182 185 190 192 198 202 204 205 212 213 223 224 225 226 229 231 240 24...
output:
163760745
result:
wrong answer 1st numbers differ - expected: '932594593', found: '163760745'