Submission #887065

#TimeUsernameProblemLanguageResultExecution timeMemory
887065chanhchuong123Trener (COCI20_trener)C++14
110 / 110
150 ms3740 KiB
#include <bits/stdc++.h> using namespace std; #define task "MAKELIST" #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() const int MOD = 1e9 + 7; int n, k; int dp[55][1505]; int hh[55][1505][3]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } cin >> n >> k; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= k; ++j) { string s; cin >> s; for (int l = 0, r = max(0, i - 2); r < i; ++l, ++r) { int hashing = 0; for (int k = l; k <= r; ++k) { hashing = 29LL * hashing % MOD; hashing += s[k] - 'a' + 1; hashing %= MOD; } if (i == 1) { hh[i][j][2] = hashing; continue; } hh[i][j][l] = hashing; if (l == 0) { hashing = 29LL * hashing % MOD; hashing += s.back() - 'a' + 1; hashing %= MOD; hh[i][j][2] = hashing; } } } } for (int j = 1; j <= k; ++j) { dp[1][j] = 1; } for (int i = 1; i < n; ++i) { for (int a = 1; a <= k; ++a) if (dp[i][a]) { for (int b = 1; b <= k; ++b) if (hh[i][a][2] == hh[i + 1][b][0] || hh[i][a][2] == hh[i + 1][b][1]) { dp[i + 1][b] += dp[i][a]; if (dp[i + 1][b] >= MOD) dp[i + 1][b] -= MOD; } } } int res = 0; for (int j = 1; j <= k; ++j) { res += dp[n][j]; if (res >= MOD) res -= MOD; } cout << res; return 0; }

Compilation message (stderr)

trener.cpp: In function 'int main()':
trener.cpp:16:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |   freopen(task".inp", "r",  stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
trener.cpp:17:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...