답안 #223218

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223218 2020-04-15T05:28:33 Z oolimry Trener (COCI20_trener) C++14
110 / 110
1987 ms 28088 KB
#include <bits/stdc++.h>

using namespace std;
long long mod = 1000000007;

unordered_map<string, long long> m;
unordered_map<string, long long> mm;

inline void prop(string s, long long x){
	//cout << s << " " << x << "\n";
	if(x == 0) return;
	for(char c = 'a';c <= 'z';c++){
		//cout << s+c << " " << c+s << "\n";
		string a = s + c;
		string b = c + s;
		long long res = mm[a];
		res += x;
		if(res >= mod) res -= mod;
		mm[a] = res;
		
		if(a != b){
			res = mm[b];
			res += x;
			if(res >= mod) res -= mod;
			mm[b] = res;
		}
	}
}

int main(){
	//freopen("i.txt","r",stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, k; cin >> n >> k;
	
	if(n == 1){
		cout << k;
		return 0;
	}
	
	for(int j = 0;j < k;j++){
		string s; cin >> s;
		prop(s, 1);
	}
	
	for(int i = 2;i <= n-1;i++){
		swap(m, mm);
		mm.clear();
		for(int j = 0;j < k;j++){
			string s; cin >> s;
			prop(s, m[s]);
		}
	}
	
	long long ans = 0;
	for(int j = 0;j < k;j++){
		string s; cin >> s;
		ans += mm[s];
		//cout << mm[s] << "\n";
	}
	
	ans %= mod;
	cout << ans;
}

# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 1912 KB Output is correct
2 Correct 62 ms 2040 KB Output is correct
3 Correct 69 ms 1916 KB Output is correct
4 Correct 41 ms 384 KB Output is correct
5 Correct 59 ms 1784 KB Output is correct
6 Correct 62 ms 1912 KB Output is correct
7 Correct 41 ms 384 KB Output is correct
# 결과 실행 시간 메모리 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 64 ms 1912 KB Output is correct
6 Correct 62 ms 2040 KB Output is correct
7 Correct 69 ms 1916 KB Output is correct
8 Correct 41 ms 384 KB Output is correct
9 Correct 59 ms 1784 KB Output is correct
10 Correct 62 ms 1912 KB Output is correct
11 Correct 41 ms 384 KB Output is correct
12 Correct 1987 ms 27964 KB Output is correct
13 Correct 1887 ms 28088 KB Output is correct
14 Correct 1812 ms 26804 KB Output is correct
15 Correct 1874 ms 24008 KB Output is correct
16 Correct 574 ms 384 KB Output is correct
17 Correct 1461 ms 23076 KB Output is correct
18 Correct 1520 ms 23804 KB Output is correct
19 Correct 1484 ms 23704 KB Output is correct
20 Correct 1507 ms 23744 KB Output is correct
21 Correct 1599 ms 23932 KB Output is correct
22 Correct 553 ms 384 KB Output is correct