Submission #312996

# Submission time Handle Problem Language Result Execution time Memory
312996 2020-10-14T22:44:14 Z anishrajeev Mate (COCI18_mate) Java 11
0 / 100
172 ms 26320 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[][][][] dpwindow = new int[2][N+1][27][27];
        dpwindow[1][1][0][s[0]] = 1;
        for(int x = 1; x < N; x++){
            dpwindow[0][1][0][s[x]] = 1;
            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;*/
                                dpwindow[0][length][i][c] += dpwindow[1][length-1][d][i];
                                dpwindow[0][length][i][c] %= mod;
                            }
                        }
                        dpwindow[0][length][i][c] += dpwindow[1][length][i][c];
                        dpwindow[0][length][i][c] %= mod;
                    }
                }
            }
            dpwindow[1] = dpwindow[0].clone();
            Arrays.fill(dpwindow[0], 0);
        }
        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(dpwindow[1][num][letter1][letter2]);
        }
        pw.close();
    }
}
# Verdict Execution time Memory Grader output
1 Runtime error 94 ms 11380 KB Execution failed because the return code was nonzero
2 Runtime error 90 ms 11152 KB Execution failed because the return code was nonzero
3 Runtime error 89 ms 10740 KB Execution failed because the return code was nonzero
4 Runtime error 92 ms 11368 KB Execution failed because the return code was nonzero
5 Runtime error 110 ms 12660 KB Execution failed because the return code was nonzero
6 Runtime error 99 ms 12572 KB Execution failed because the return code was nonzero
7 Runtime error 101 ms 12896 KB Execution failed because the return code was nonzero
8 Runtime error 101 ms 12408 KB Execution failed because the return code was nonzero
9 Runtime error 172 ms 26320 KB Execution failed because the return code was nonzero
10 Runtime error 160 ms 25588 KB Execution failed because the return code was nonzero