# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
293456 |
2020-09-08T05:47:33 Z |
updown1 |
Mate (COCI18_mate) |
Java 11 |
|
1295 ms |
131072 KB |
import java.util.*;
import java.io.*;
public class mate {
public static void main(String[] args) throws IOException{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
String str = bf.readLine();
int mod = 1000000007;
char[] array = new char[str.length()];
int N = array.length;
for(int i = 0; i < str.length(); i++)array[i] = str.charAt(i);
int[] s = new int[N];
for(int i = 0; i < N; i++)s[i] = array[i]-96;
int [][][][] dp = new int[N][N+1][27][27];
for(int i = 0; i < N; i++){
/*for(int c = i; c >= 0; c--){
int num = array[c]-96;
//dp[i][1][num][0] = 1;
dp[i][1][0][num] = 1;
}*/
dp[i][1][0][s[i]] = 1;
}
for(int x = 1; x < N; x++){
for(int length = 1; length <= N; length++){
for(int i = 0; i <= 26; i++){
for(int c = 0; c <= 26; c++){
if(c == s[x]){
for(int d = 0; d <= 26; d++){
dp[x][length][i][c] += dp[x-1][length-1][d][i];
dp[x][length][i][c] %= mod;
}
}
//else{
dp[x][length][i][c] += dp[x-1][length][i][c];
dp[x][length][i][c] %= mod;
//}
/*if (dp[x][length][i][c] != 0) {
System.out.println(x + " " + length + " " + i + " " + c + ": " + dp[x][length][i][c]);
if(c == s[x-1]){
System.out.println("match " + c);
}
}*/
}
}
}
}
int Q = Integer.parseInt(bf.readLine());
for(int i = 0; i < Q; i++){
StringTokenizer stk = new StringTokenizer(bf.readLine());
int num = Integer.parseInt(stk.nextToken());
String[] XY = stk.nextToken().split("");
int letter1 = XY[0].charAt(0)-96;
int letter2 = XY[1].charAt(0)-96;
pw.println(dp[N-1][num][letter1][letter2]);
}
pw.close();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
796 ms |
62944 KB |
Output is correct |
2 |
Correct |
521 ms |
47448 KB |
Output is correct |
3 |
Correct |
613 ms |
51636 KB |
Output is correct |
4 |
Correct |
861 ms |
69296 KB |
Output is correct |
5 |
Runtime error |
1061 ms |
131072 KB |
Execution killed with signal 9 |
6 |
Runtime error |
1078 ms |
131072 KB |
Execution killed with signal 9 |
7 |
Runtime error |
1260 ms |
131072 KB |
Execution killed with signal 9 |
8 |
Runtime error |
1295 ms |
131072 KB |
Execution killed with signal 9 |
9 |
Runtime error |
1206 ms |
131072 KB |
Execution killed with signal 9 |
10 |
Runtime error |
1157 ms |
131072 KB |
Execution killed with signal 9 |