Submission #251449

#TimeUsernameProblemLanguageResultExecution timeMemory
251449VEGAnnKlavir (COCI17_klavir)C++14
16 / 160
183 ms28028 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...