QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#364542 | #547. BM 算法 | Xiaohuba | WA | 144ms | 3756kb | C++23 | 3.7kb | 2024-03-24 15:11:42 | 2024-03-24 15:11:43 |
Judging History
This is the latest submission verdict.
- [2024-12-28 21:37:58]
- hack成功,自动添加数据
- (/hack/1317)
- [2024-03-24 15:11:42]
- Submitted
answer
#include <bits/stdc++.h>
using namespace std;
// #define LOCK_GETCHAR
// #define USE_INT_128
#if __cplusplus < 201400
#warning "Please use c++14 or higher."
#define CONSTEXPR_FUNC
#define ENABLE_IF_INT
#else
#define CONSTEXPR_FUNC constexpr
#define ENABLE_IF_INT , enable_if_t<_is_integer<T>, int> = 0
template <class T> constexpr bool _is_integer = numeric_limits<T>::is_integer;
template <> constexpr bool _is_integer<bool> = false;
template <> constexpr bool _is_integer<char> = false;
#ifdef USE_INT_128
template <> constexpr bool _is_integer<__int128> = true;
template <> constexpr bool _is_integer<__uint128_t> = true;
#endif
template <class T ENABLE_IF_INT>
constexpr T INF = numeric_limits<T>::max() >> 1;
#endif
#if !defined(_WIN32) && !defined(LOCK_GETCHAR)
#define getchar getchar_unlocked
#endif
#define il inline
#define mkp make_pair
#define fi first
#define se second
#define For(i, j, k) for (decltype(j - k) i = (j); i <= (k); ++i) // NOLINT
#define ForDown(i, j, k) for (decltype(j - k) i = (j); i >= (k); --i) // NOLINT
#define pb push_back
#define eb emplace_back
#ifndef ONLINE_JUDGE
#define FileIO(filename) \
freopen(filename ".in", "r", stdin); \
freopen(filename ".out", "w", stdout)
#else
#define FileIO(filename) void(0)
#endif
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
using db = double;
using ldb = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#ifdef USE_INT_128
using lll = __int128_t;
using ulll = __uint128_t;
#endif
// clang-format off
template<typename T> constexpr il T sq(const T & x){ return x * x; }
template<typename T> CONSTEXPR_FUNC il void cmin(T & x, const T &y){ x = min(x, y); }
template<typename T> CONSTEXPR_FUNC il void cmax(T & x, const T &y){ x = max(x, y);}
template<typename T> CONSTEXPR_FUNC il T qpow(T x, ull y, T mod){T ans = 1; x %= mod; while (y) { if(y & 1)(ans *= x) %= mod;(x *= x) %= mod; y >>= 1;} return ans;}
template<typename T> CONSTEXPR_FUNC il T qpow(T x, ull y){T ans = 1; while (y) {if(y & 1) ans *= x;x *= x;y >>= 1;} return ans;}
template<typename T ENABLE_IF_INT> il void read(T &x){ x = 0; int f = 1; int c = getchar(); while(!isdigit(c)) {if (c == '-') f = -1;c = getchar();} while(isdigit(c)) {x = x * 10 + c - '0';c = getchar();} x *= f;}
template<typename T, typename ... Args> il void read(T &x, Args &... y){ read(x); read(y...); }
// clang-format on
// File head end
namespace {
constexpr ll MAXN = 1e4 + 5, mod = 998244353;
il vector<ll> BM(vector<ll> &a) {
int n = a.size(), k = -1;
ll delta = 0;
vector<ll> F, lst;
For(i, 0, n - 1) {
ll val = 0;
For(j, 0, signed(F.size()) - 1)(val += F[j] * a[i - j - 1]) %= mod;
if (val == a[i])
continue;
else if (!(~k))
delta = mod - a[i], F.resize(i + 1), k = i;
else {
ll new_dlt = (mod + val - a[i]) % mod,
mul = new_dlt * qpow(delta, mod - 2, mod) % mod;
vector<ll> G = F;
if (G.size() < lst.size() + i - k)
G.resize(lst.size() + i - k);
G[i - k - 1] += mul % mod;
// cerr << i - k - 1 << ' ' << new_dlt << ' ' << delta << '\n';
For(j, 0, signed(lst.size()) - 1) {
(G[i - k + j] += mod - lst[j] * mul % mod) %= mod;
}
F.swap(G);
if (signed(G.size()) - i < signed(lst.size()) - k) {
delta = new_dlt, k = i, lst = G;
}
}
}
return F;
}
il void Main() {
int n;
read(n);
vector<ll> a(n);
For(i, 0, n - 1) read(a[i]);
auto res = BM(a);
cout << res.size() << '\n';
for (int x : res)
cout << x << ' ';
cout << '\n';
}
} // namespace
signed main() { return Main(), 0; }
详细
Test #1:
score: 0
Wrong Answer
time: 144ms
memory: 3756kb
input:
10000 481761257 325845401 89198273 331256176 423285801 510703206 160079009 805700484 2785453 119847482 4456012 47414124 382685410 463638256 314056646 483110670 723760177 473280072 294639899 965560586 243267953 822936984 475063108 193430844 842374415 125382693 569285769 643640101 548245375 253979925 ...
output:
5000 -1775444830 819131002 649493734 47951480 65996429 624850962 739269648 845796901 402791943 477864808 694250586 473539973 259723476 874936566 738958318 614776198 265123599 688249985 374535847 667211821 656867177 924040313 487671109 465655759 265111423 671579567 816162555 408914663 554404795 12141...
result:
wrong answer you didn't minimize k