답안 #312995

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
312995 2020-10-14T22:42:21 Z anishrajeev Mate (COCI18_mate) Java 11
80 / 100
2000 ms 93544 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;
                    }
                }
            }
            for(int i = 1; i <= N; i++){
                for(int c = 0; c <= 26; c++){
                    for(int d = 0; d <= 26; d++){
                        dpwindow[1][i][c][d] = dpwindow[0][i][c][d];
                        dpwindow[0][i][c][d] = 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();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 646 ms 52640 KB Output is correct
2 Correct 529 ms 39832 KB Output is correct
3 Correct 559 ms 43128 KB Output is correct
4 Correct 757 ms 55060 KB Output is correct
5 Correct 1500 ms 93544 KB Output is correct
6 Correct 1566 ms 66132 KB Output is correct
7 Correct 1492 ms 62376 KB Output is correct
8 Correct 1331 ms 77368 KB Output is correct
9 Execution timed out 2025 ms 27636 KB Time limit exceeded
10 Execution timed out 2019 ms 28136 KB Time limit exceeded