Submission #2245496


Source Code Expand

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        private const int M = 1000000007;

        private static int Solve(int N, string S1, string S2)
        {
            long res = (S1[0] == S2[0]) ? 3 : 6;
            int n1   = (S1[0] == S2[0]) ? 1 : 2;
            for (int i = 1; i < N; ++i)
            {
                int n2 = (S1[i] == S2[i]) ? 1 : 2;
                if (n2 == 1)
                {
                    res *= (n1 == 1) ? 2 : 1;
                }
                else if (S1[i - 1] != S1[i])
                {
                    res *= (n1 == 1) ? 2 : 3;
                }
                res %= M;
                n1 = n2;
            }
            return (int)res;
        }

        static void Main(string[] args)
        {
            int N = ReadInt();
            string S1 = Read();
            string S2 = Read();
            Console.WriteLine(Solve(N, S1, S2));
        }
    }
}

Submission Info

Submission Time
Task D - Coloring Dominoes
User M_Saito
Language C# (Mono 4.6.2.0)
Score 400
Code Size 1680 Byte
Status AC
Exec Time 21 ms
Memory 13140 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 20 ms 9044 KB
10.txt AC 20 ms 11092 KB
11.txt AC 20 ms 11092 KB
12.txt AC 20 ms 11092 KB
13.txt AC 20 ms 11220 KB
14.txt AC 20 ms 9044 KB
15.txt AC 20 ms 9044 KB
16.txt AC 20 ms 11220 KB
17.txt AC 20 ms 11092 KB
18.txt AC 20 ms 11092 KB
19.txt AC 20 ms 11092 KB
2.txt AC 19 ms 9044 KB
20.txt AC 21 ms 13140 KB
21.txt AC 20 ms 9044 KB
22.txt AC 20 ms 11092 KB
3.txt AC 19 ms 9044 KB
4.txt AC 19 ms 9044 KB
5.txt AC 20 ms 11092 KB
6.txt AC 20 ms 11092 KB
7.txt AC 20 ms 13140 KB
8.txt AC 20 ms 11092 KB
9.txt AC 20 ms 11092 KB
sample1.txt AC 20 ms 11220 KB
sample2.txt AC 20 ms 11092 KB
sample3.txt AC 20 ms 9044 KB