# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
205033 | MetB | Klavir (COCI17_klavir) | C++14 | 243 ms | 23964 KiB |
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>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define N 1000001
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll INF = 1e18, MOD = 1e9 + 7, MOD2 = 1e6 + 3;
int n, m;
ll pf[N], pw[N], s[N];
int main () {
cin >> n;
cin >> m;
pw[0] = 1;
for (int i = 1; i <= m; i++)
pw[i] = n * pw[i-1] % MOD;
for (int i = 0; i < m; i++) {
cin >> s[i];
}
for (int i = 1; i < m; i++) {
int j = pf[i-1];
while (j > 0 && s[j] != s[i])
j = pf[j-1];
if (s[i] == s[j]) j++;
pf[i] = j;
}
ll ans = n;
cout << n << '\n';
for (int i = 1; i < n; i++) {
int l = i - 1, r = i;
while (l != r) {
if (l > r) {
ans = (ans + MOD - pw[l+1]) % MOD;
l = pf[l] - 1;
}
if (l < r) {
ans = (ans + pw[r+1]) % MOD;
r = pf[r] - 1;
}
}
cout << ans << '\n';
}
}
Compilation message (stderr)
# | 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... |