QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#833365 | #2354. Ook | I_Love_Sonechka# | WA | 1ms | 3856kb | C++20 | 2.8kb | 2024-12-26 18:06:07 | 2024-12-26 18:06:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifdef ONPC
#define deb(...) cerr << '[' << __LINE__ << "] (" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define deb(...)
#endif
// c++ short types
#define vt vector
//typedef long long ll;
typedef long double ld;
void whattime() { cout << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl; }
// const int mod = 1e9 + 7;
const int mod = 998244353;
const int inf = 1e9;
const int64_t infll = 1e13;
bool debug = false;
const ld eps = 1e-9;
const ld pi = acos(-1);
mt19937_64 rng((int) chrono::steady_clock::now().time_since_epoch().count());
const int max_K = 31;
bool equal(char a, char b) {
return a == '?' || b == '?' || a == b;
}
vt<vt<int>> pfun(const string &s, int a) {
vt<vt<int>> p(s.size(), vt<int>(max_K, 0));
for(int i = a; i < (int)s.size(); ++i) {
for(int j = 0; j < max_K; ++j) {
int g = p[i-1][j];
while(g && !equal(s[i], s[g])) g = p[g-1][j];
p[i][j] = g + equal(s[i], s[g]);
}
for(int j = 0; j + 1 < max_K; ++j) {
p[i][j+1] = max(p[i][j+1], p[i-1][j] + 1);
}
}
return p;
}
void solve() {
int o, k;
cin >> o >> k;
string s, p;
cin >> s >> p;
auto pi = pfun(p + "#" + s, p.size()+1);
vt<int> what(s.size(), max_K);
for(int i = p.size() + 1; i < s.size() + p.size() + 1; ++i) {
for(int j = 0; j < max_K; ++j) if(pi[i][j] >= p.size()) {
what[i - p.size() - 1] = j;
break;
}
}
int cost = 0;
vt<int> dp(s.size(), 0), vertices(40, 0);
for(int i = 0; i < int(s.size()); ++i) {
if(i) {
dp[i] = dp[i-1];
}
if(i >= p.size()) {
if(s[i - p.size()] == 'o') {
cost -= o;
} else {
cost -= k;
}
}
if(s[i] == 'o') {
cost += o;
} else {
cost += k;
}
if(i + 1 >= p.size()) {
int value = cost >> what[i];
if(i >= p.size()) {
value += dp[i-p.size()];
}
dp[i] = max(dp[i], value);
}
}
cout << dp.back() << '\n';
}
int main()
{
// ios::sync_with_stdio(false); cin.tie(nullptr);
#ifdef ONPC
freopen("C:\\Users\\raf4i\\CLionProjects\\cp\\inp.txt", "r", stdin);
#endif
int tt = 1;
if(debug) {
tt = 1e6;
} else {
// cin >> tt;
}
for(int t = 0; t < tt; ++t) {
solve();
}
#ifdef ONPC
whattime();
#endif
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3672kb
input:
2 1 ookookook koo
output:
10
result:
ok single line: '10'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3812kb
input:
1 3 koooooook ?
output:
13
result:
ok single line: '13'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3812kb
input:
1000 0 kookoo ook
output:
2000
result:
ok single line: '2000'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3856kb
input:
21 1 ooo kkk
output:
7
result:
ok single line: '7'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3684kb
input:
1 0 ookko k??ko
output:
1
result:
ok single line: '1'
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 3552kb
input:
5 8 koookokkok oo
output:
28
result:
wrong answer 1st lines differ - expected: '32', found: '28'