QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#377584 | #8278. Secret Poems | PetroTarnavskyi# | WA | 0ms | 3556kb | C++20 | 1.9kb | 2024-04-05 15:37:38 | 2024-04-05 15:37:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int mod = 998244353;
void updAdd(int& a, int b)
{
a += b;
if (a >= mod)
a -= mod;
}
int add(int a, int b)
{
return a + b < mod ? a + b : a + b - mod;
}
int mult(int a, int b)
{
return (LL)a * b % mod;
}
int binpow(int a, int n)
{
int res = 1;
while (n)
{
if (n & 1)
res = mult(res, a);
a = mult(a, a);
n >>= 1;
}
return res;
}
void solve()
{
int n, T;
cin >> n >> T;
VI a(n), t(n);
for (int& ai : a)
cin >> ai;
for (int& ti : t)
cin >> ti;
if (accumulate(ALL(t), 0LL) <= T)
{
int ans = 0;
for (int ai : a)
updAdd(ans, ai);
FOR(i, 0, n)
ans = mult(ans, 2);
cout << ans << "\n";
return;
}
int ans = 0;
FOR(it, 0, 2)
{
VI cnt(T + 1), sum(T + 1);
cnt[0] = 1;
LL sumt = accumulate(ALL(t), 0LL), suma = accumulate(ALL(a), 0LL);
FOR(i, 0, n)
{
sumt -= t[i];
suma -= a[i];
if (it == 0)
{
int cur = 0;
FOR(j, T - t[i] + 1, T + 1)
{
updAdd(cur, sum[j]);
}
updAdd(ans, mult(cur, binpow(2, n - i - 1)));
}
else
{
int cur = 0;
FOR(j, max(0LL, T - sumt - t[i] + 1), T - sumt + 1)
{
updAdd(cur, add(mult(cnt[j], suma), sum[j]));
}
updAdd(ans, mult(cur, binpow(2, n - i - 1)));
}
RFOR(j, T - t[i] + 1, 0)
{
updAdd(cnt[j + t[i]], cnt[j]);
updAdd(sum[j + t[i]], add(sum[j], mult(a[i], cnt[j])));
}
}
}
cout << ans << "\n";
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3556kb
input:
5 THSAD IIVOP SEOOH RGETI YMINK
output:
0
result:
wrong answer 1st lines differ - expected: 'THISI', found: '0'