Submission #246314

# Submission time Handle Problem Language Result Execution time Memory
246314 2020-07-08T15:57:24 Z alrad Trener (COCI20_trener) C++17
55 / 110
2000 ms 17404 KB
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()

const int N = 100 + 2;
const int MOD = 1e9 + 7;

int main() {
   #ifdef judge
      ifstream cin("input.txt");
   #endif // judge
   ios_base :: sync_with_stdio(0);
   cin.tie(0) , cout.tie(0);
   int n , k;
   cin >> n >> k;
   string full[n][k] , pref[n][k] , suf[n][k];
   for (int i = 0; i < n; i++) {
      for (int j = 0; j < k; j++) {
         cin >> full[i][j];
         if (i > 0) {
            pref[i][j] = full[i][j].substr(0 , i);
            suf[i][j] = full[i][j].substr(1 , i);
         }
      }
   }
   vector<vector<int> > dp(n , vector<int>(k , 0));
   for (int j = 0; j < k; j++) {
      dp[0][j] = 1;
   }
   for (int i = 1; i < n; i++) {
      for (int cur = 0; cur < k; cur++) {
         for (int prev = 0; prev < k; prev++) {
            if (full[i - 1][prev] == pref[i][cur] || full[i - 1][prev] == suf[i][cur]) {
               dp[i][cur] += dp[i - 1][prev];
               dp[i][cur] %= MOD;
            }
         }
      }
   }
   int ans = 0;
   for (int j = 0; j < k; j++) {
      ans += dp[n - 1][j];
      ans %= MOD;
   }
   cout << ans << '\n';
   return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1408 KB Output is correct
2 Correct 15 ms 1536 KB Output is correct
3 Correct 13 ms 1536 KB Output is correct
4 Correct 10 ms 1536 KB Output is correct
5 Correct 22 ms 1408 KB Output is correct
6 Correct 17 ms 1408 KB Output is correct
7 Correct 13 ms 1428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 13 ms 1408 KB Output is correct
6 Correct 15 ms 1536 KB Output is correct
7 Correct 13 ms 1536 KB Output is correct
8 Correct 10 ms 1536 KB Output is correct
9 Correct 22 ms 1408 KB Output is correct
10 Correct 17 ms 1408 KB Output is correct
11 Correct 13 ms 1428 KB Output is correct
12 Correct 1521 ms 17308 KB Output is correct
13 Correct 1566 ms 17300 KB Output is correct
14 Correct 1565 ms 17300 KB Output is correct
15 Correct 1504 ms 17404 KB Output is correct
16 Correct 1014 ms 17300 KB Output is correct
17 Execution timed out 2058 ms 17272 KB Time limit exceeded
18 Halted 0 ms 0 KB -