QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#601383 | #975. Game | fractal# | TL | 1ms | 5756kb | C++17 | 861b | 2024-09-29 22:43:54 | 2024-09-29 22:43:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sz(x) (int)x.size()
const int N = 1e6;
long long n;
long long a[N];
long long dp[N];
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
a[i] *= 2;
}
dp[1] = a[1];
for (int i = 2; i <= n; ++i) {
dp[i] = 0;
for (int j = max(1, i - 10000); j < i; ++j) {
dp[i] = max(dp[i], dp[j] + (a[i] + a[j]) / 2 * (i - j - 1) + a[i]);
}
}
long long ans = dp[n];
long long r = 1;
n *= 2;
const int mod = 998244353;
long long pw = mod - 2;
while (pw) {
if (pw & 1) r = (r * n) % mod;
n = (n * n) % mod;
pw /= 2;
}
ans = (ans * r) % mod;
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5756kb
input:
3 3 1 2
output:
499122179
result:
ok "499122179"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5700kb
input:
6 6 1 2 5 3 4
output:
582309211
result:
ok "582309211"
Test #3:
score: -100
Time Limit Exceeded
input:
500000 131592496991 614154464278 882215024371 954828734583 997777248498 677111110098 927405745589 218490006270 743425189504 391435077446 972647376673 630405853326 714899101544 90679613430 530369364312 763893201576 838136940841 261795310871 187042095193 941416320169 688136558810 554872601435 54089147...