답안 #456260

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
456260 2021-08-06T09:54:26 Z grt Trener (COCI20_trener) C++17
110 / 110
91 ms 2500 KB
#include <bits/stdc++.h>
#define ST first
#define ND second
#define PB push_back

using namespace std;
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;

const int mod = 1e9 + 7, p = 31;
int n, k;
map<int,int>opt, opt2;


int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> k;
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < k; ++j) {
			string s;
			cin >> s;
			int h = 0;
			int h2 = 0;
			int h3 = 0;
			for(auto c : s) {
				h2 = h;
				if(h != 0) {
					h3 = ((ll)h3 * p + (c - 'a' + 1)) % mod;
				}
				h = ((ll)h * p + (c - 'a' + 1)) % mod;
			}
			//cout << h << " " << h2 << " " << h3 << "\n";
			if(i == 0) {
				opt2[h]++;
			} else {
				opt2[h] = (opt2[h] + opt[h2]) % mod;
				if(h3 != h2)
				opt2[h] = (opt2[h] + opt[h3]) % mod;
			}
		}
		opt.swap(opt2);
		opt2.clear();
	}
	int ans = 0;
	for(auto it : opt) {
		ans = (ans + it.ND) % mod;
	}	
	cout << ans;	
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 460 KB Output is correct
2 Correct 6 ms 332 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 4 ms 460 KB Output is correct
6 Correct 4 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 6 ms 460 KB Output is correct
6 Correct 6 ms 332 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 4 ms 460 KB Output is correct
10 Correct 4 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 78 ms 2412 KB Output is correct
13 Correct 91 ms 2408 KB Output is correct
14 Correct 82 ms 2412 KB Output is correct
15 Correct 80 ms 2408 KB Output is correct
16 Correct 29 ms 2212 KB Output is correct
17 Correct 69 ms 2364 KB Output is correct
18 Correct 67 ms 2368 KB Output is correct
19 Correct 67 ms 2500 KB Output is correct
20 Correct 67 ms 2368 KB Output is correct
21 Correct 66 ms 2368 KB Output is correct
22 Correct 28 ms 2216 KB Output is correct