Submission #845438

# Submission time Handle Problem Language Result Execution time Memory
845438 2023-09-06T13:37:33 Z vjudge1 Trener (COCI20_trener) C++17
110 / 110
125 ms 25936 KB
#include <bits/stdc++.h>
using namespace std;
#define sp " "
#define endl "\n";
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define N 2005
#define int long long

const int modulo = 1e9 + 7;


int dp[N], dpold[N];

int add(int a, int b){
	if (a + b < modulo) return a + b;
	return a + b - modulo;
}


int32_t main()
{
	fastio();

	int n, k;
	cin>>n>>k;
	vector<string> arr[n + 5];
	map<string, vector<int>> ind[N];

	for (int i = 1; i <= n; i++){
		for (int j = 0; j < k; j++)
		{
			string tmp;
			cin>>tmp;
			arr[i].pb(tmp);
			ind[i][tmp].pb(j);
		}
	}

	for (int i = 0; i <= k; i++){
		dpold[i] = 1;
	}

	for (int i = n; i >= 2; i--){
		for (int j = 0; j < k; j++){
			//cout<<i<<sp<<dpold[j]<<endl;
			string a = "";
			for (int l = 1; l < arr[i][j].size(); l++)
				a.pb(arr[i][j][l]);
			for (auto l : ind[i - 1][a])
				dp[l] = add(dp[l], dpold[j]);

			string b = "";
			for (int l = 0; l + 1 < arr[i][j].size(); l++)
				b.pb(arr[i][j][l]);

			if (a == b) continue;
			for (auto l : ind[i - 1][b])
				dp[l] = add(dp[l], dpold[j]);
		}

		for (int j = 0; j < k; j++)
			dpold[j] = dp[j], dp[j] = 0;
	}

	int ans = 0;
	for (int i = 0; i < k; i++)
		ans = add(ans, dpold[i]);
	cout<<ans<<endl;
	cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " seconds\n";
}

Compilation message

trener.cpp: In function 'int32_t main()':
trener.cpp:51:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |    for (int l = 1; l < arr[i][j].size(); l++)
      |                    ~~^~~~~~~~~~~~~~~~~~
trener.cpp:57:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |    for (int l = 0; l + 1 < arr[i][j].size(); l++)
      |                    ~~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2392 KB Output is correct
2 Correct 5 ms 2136 KB Output is correct
3 Correct 6 ms 2136 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 5 ms 1880 KB Output is correct
6 Correct 5 ms 1880 KB Output is correct
7 Correct 3 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 5 ms 2392 KB Output is correct
6 Correct 5 ms 2136 KB Output is correct
7 Correct 6 ms 2136 KB Output is correct
8 Correct 3 ms 860 KB Output is correct
9 Correct 5 ms 1880 KB Output is correct
10 Correct 5 ms 1880 KB Output is correct
11 Correct 3 ms 856 KB Output is correct
12 Correct 111 ms 25936 KB Output is correct
13 Correct 115 ms 25892 KB Output is correct
14 Correct 113 ms 25936 KB Output is correct
15 Correct 111 ms 25936 KB Output is correct
16 Correct 123 ms 6496 KB Output is correct
17 Correct 91 ms 19364 KB Output is correct
18 Correct 92 ms 19280 KB Output is correct
19 Correct 92 ms 19352 KB Output is correct
20 Correct 94 ms 19408 KB Output is correct
21 Correct 97 ms 19280 KB Output is correct
22 Correct 125 ms 6488 KB Output is correct