Submission #205038

# Submission time Handle Problem Language Result Execution time Memory
205038 2020-02-27T17:53:27 Z MetB Klavir (COCI17_klavir) C++14
160 / 160
375 ms 41592 KB
#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], ans[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;
	}

    ans[0] = n;
    cout << ans[0] << '\n';
    for (int i = 1; i < m; i++) {
        ans[i] = pw[i+1] + (pf[i] ? ans[pf[i]-1] : 0);
		ans[i] %= MOD;
        cout << ans[i] << '\n';
    }
}

Compilation message

klavir.cpp: In function 'int main()':
klavir.cpp:24:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for (int i = 1; i <= m; i++)
     ^~~
klavir.cpp:27:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  for (int i = 0; i < m; i++) {
  ^~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 4472 KB Output is correct
2 Correct 335 ms 40556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 358 ms 41532 KB Output is correct
2 Correct 338 ms 40576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 375 ms 41592 KB Output is correct
2 Correct 331 ms 40568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 365 ms 41524 KB Output is correct
2 Correct 343 ms 40568 KB Output is correct