結果
| 問題 | No.2332 Make a Sequence |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-05-01 14:06:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,628 bytes |
| コンパイル時間 | 956 ms |
| コンパイル使用メモリ | 104,720 KB |
| 最終ジャッジ日時 | 2025-02-12 16:17:22 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 46 WA * 15 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:41:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
41 | for (auto &&i : A) scanf("%d", &i);
| ~~~~~^~~~~~~~~~
main.cpp:43:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
43 | for (auto &&i : B) scanf("%d", &i);
| ~~~~~^~~~~~~~~~
main.cpp:45:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
45 | for (auto &&i : C) scanf("%d", &i);
| ~~~~~^~~~~~~~~~
ソースコード
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
#include <limits>
static const int MOD = 998244353;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
vector<int> Z_algorithm(const vector<int> &s){
vector<int> res(s.size());
for (int i = 1, j = 0; i < s.size(); ++i) {
if(i + res[i-j] < j + res[j]) res[i] = res[i-j];
else {
int k = max(0, j + res[j]-i);
while(i + k < s.size() && s[k] == s[i+k]) ++k;
res[i] = k;
j = i;
}
}
res.front() = s.size();
return res;
}
int main() {
int n, m;
cin >> n >> m;
vector<int> A(n);
for (auto &&i : A) scanf("%d", &i);
vector<int> B(m);
for (auto &&i : B) scanf("%d", &i);
vector<int> C(m);
for (auto &&i : C) scanf("%d", &i);
vector<ll> idx(m+2);
iota(idx.begin(),idx.end(), 0);
vector<int> AB(n+m+1);
for (int i = 0; i < n; ++i) {
AB[i] = A[i];
}
for (int i = 0; i < m; ++i) {
AB[i+n] = B[i];
}
auto Z = Z_algorithm(AB);
vector<ll> dp(m+1, INF<ll>);
dp[0] = 0;
for (int i = 0; i < m; ++i) {
for (int j = i+1; j <= i+Z[n+i]; ++j) {
if(dp[j] >= dp[i] + (ll)C[i]*(j-i)){
dp[j] = dp[i] + (ll)C[i]*(j-i);
}else break;
}
}
if(dp[m] == INF<ll>) puts("-1");
else cout << dp[m] << "\n";
return 0;
}