This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int md = 998244353;
const int M = 1000100;
int n, m, a[M], po[M], ans[M], pf[M];
int mult(int x, int y) { return (1ll * x * y) % md; }
int sum(int x, int y){
x += y;
if (x >= md)
x -= md;
return x;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n >> m;
po[0] = 1;
for (int i = 0; i < m; i++) {
cin >> a[i];
po[i + 1] = mult(po[i], n);
}
pf[0] = 0;
for (int i = 1; i < m; i++){
int j = pf[i - 1];
while (j > 0 && a[j] != a[i])
j = pf[j - 1];
if (a[j] == a[i])
j++;
pf[i] = j;
}
for (int i = 1; i <= m; i++){
ans[i] = sum(ans[pf[i - 1]], po[i]);
cout << ans[i] << " ";
}
return 0;
}
# | 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... |
# | 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... |