이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;
#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout (T t, U...u) {cout << t << (sizeof... (u) ? ", " : ""), dout (u...);}
#else
#define debug(...) 7122
#endif
#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second
const ll base = 1e9 + 9;
const ll MOD = 1000000000000037ll;
const ll INF = 1e18;
const int SIZE = 2505;
int n;
string s;
int A, B, C;
ll dp[SIZE][SIZE];
int nxt[SIZE];
ll pro[SIZE], inv[SIZE], pre[SIZE];
ll power(ll d, ll up) {
ll re = 1;
while (up) {
if (up & 1) re = (__int128) re * d % MOD;
d = (__int128) d * d % MOD;
up >>= 1;
}
return re;
}
ll cal(int l, int r) {
ll x = pre[r] - pre[l - 1];
if (x < 0) x += MOD;
return (__int128) x * inv[l] % MOD;
}
void solve() {
cin >> n >> s;
cin >> A >> B >> C;
s = " " + s;
pro[0] = inv[0] = 1;
inv[1] = power(base, MOD - 2);
FOR (i, 1, n) {
pro[i] = (__int128) pro[i - 1] * base % MOD;
inv[i] = (__int128) inv[i - 1] * inv[1] % MOD;
pre[i] = (pre[i - 1] + (__int128) pro[i] * s[i]) % MOD;
}
FOR (i, 1, n) FOR (j, i, n) dp[i][j] = INF;
FOR (len, 1, n) {
unordered_map<int, int> pos;
unordered_map<int, vector<int>> mp;
for (int l = 1, r = len; r <= n; l++, r++) {
dp[l][r] = min(dp[l][r], min(dp[l][r - 1], dp[l + 1][r]) + A);
int val = cal(l, r);
pos[val] = 0;
mp[val].pb(l);
}
for (int l = 1, r = len; r <= n; l++, r++) {
int val = cal(l, r);
while (pos[val] < mp[val].size() && mp[val][pos[val]] <= r) pos[val]++;
if (pos[val] == mp[val].size()) nxt[l] = n + 1;
else nxt[l] = mp[val][pos[val]];
}
for (int l = 1, r = len; r <= n; l++, r++) {
int pl = l, pr = r, cnt = 1;
while (pr <= n) {
dp[l][pr] = min(dp[l][pr], dp[l][r] + B + 1ll * C * cnt + 1ll * A * (pr - l + 1 - len * cnt));
pl = nxt[pl];
pr = pl + len - 1;
cnt++;
}
}
}
cout << dp[1][n] << '\n';
}
int main() {
Waimai;
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
copypaste3.cpp: In function 'void solve()':
copypaste3.cpp:72:29: warning: comparison of integer expressions of different signedness: 'std::unordered_map<int, int>::mapped_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | while (pos[val] < mp[val].size() && mp[val][pos[val]] <= r) pos[val]++;
copypaste3.cpp:73:26: warning: comparison of integer expressions of different signedness: 'std::unordered_map<int, int>::mapped_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | if (pos[val] == mp[val].size()) nxt[l] = n + 1;
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |