Submission #2526225


Source Code Expand

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int n;
    char[][] ss;
    int MOD = 1000000007;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        ss = new char[2][n];
        for (int i = 0; i < 2; i++) {
            ss[i] = sc.next().toCharArray();
        }
        solve();
    }

    void solve() {
        long num = 1;
        int prevBlock = 0;
        for (int i = 0; i < n; i++) {
            if (ss[0][i] == ss[1][i]) {
                switch (prevBlock) {
                    case 0:
                        num *= 3;
                        break;
                    case 1:
                        num *= 2;
                        break;
                }
                num %= MOD;
                prevBlock = 1;
            } else {
                switch (prevBlock) {
                    case 0:
                        num *= 6;
                        break;
                    case 1:
                        num *= 2;
                        break;
                    case 2:
                        num *= 3;
                        break;
                }
                num %= MOD;
                prevBlock = 2;
                i++;
            }
        }
        System.out.println(num);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Submission Info

Submission Time
Task D - Coloring Dominoes
User ynish
Language Java8 (OpenJDK 1.8.0)
Score 400
Code Size 2724 Byte
Status AC
Exec Time 72 ms
Memory 22740 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 28
Set Name Test Cases
Sample sample1.txt, sample2.txt, sample3.txt
All sample1.txt, sample2.txt, sample3.txt, 1.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 2.txt, 20.txt, 21.txt, 22.txt, 3.txt, 4.txt, 5.txt, 6.txt, 7.txt, 8.txt, 9.txt, sample1.txt, sample2.txt, sample3.txt
Case Name Status Exec Time Memory
1.txt AC 71 ms 18772 KB
10.txt AC 71 ms 19668 KB
11.txt AC 69 ms 19668 KB
12.txt AC 68 ms 19156 KB
13.txt AC 67 ms 19284 KB
14.txt AC 68 ms 19028 KB
15.txt AC 69 ms 17364 KB
16.txt AC 69 ms 21332 KB
17.txt AC 69 ms 18260 KB
18.txt AC 69 ms 19284 KB
19.txt AC 69 ms 22740 KB
2.txt AC 69 ms 17364 KB
20.txt AC 69 ms 19028 KB
21.txt AC 70 ms 19156 KB
22.txt AC 72 ms 18900 KB
3.txt AC 69 ms 18772 KB
4.txt AC 70 ms 19156 KB
5.txt AC 71 ms 21076 KB
6.txt AC 71 ms 20436 KB
7.txt AC 70 ms 19284 KB
8.txt AC 70 ms 21076 KB
9.txt AC 70 ms 18900 KB
sample1.txt AC 68 ms 19284 KB
sample2.txt AC 68 ms 18004 KB
sample3.txt AC 71 ms 20948 KB