Submission #2995589


Source Code Expand

Copy
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    ReadData re;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        re = new ReadData();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        int H = re.i();
        int W = re.i();
        int[] Rev = new int[1000];
        for(int i=1;i<1000;i++){
            int c = i;
            while(c % 10 == 0){
                c /= 10;
            }
            if(c < 10){
                Rev[i] = c;
            }
            else if(c < 100){
                Rev[i] = (c % 10) * 10 + c /10;
            }
            else{
                Rev[i] = (c % 10) * 100 + (c / 10 % 10) * 10 + c / 100;
            }
        }
        List<int>[] G = new List<int>[1000000];
        for(int i=0;i<1000000;i++){
            G[i] = new List<int>();
        }
        for(int i=1;i<=999;i++){
            for(int j=1;j<=999;j++){
                int x = i;
                int y = j;
                if(x < y){
                    x = Rev[x];
                }
                else{
                    y = Rev[y];
                }
                if(x < y){
                    y -= x;
                }
                else{
                    x -= y;
                }
                G[x*1000+y].Add(i*1000+j);
            }
        }
        bool[] Achieved = new bool[1000000];
        for(int i=0;i<1000;i++){
            dfs(i*1000,Achieved,G);
        }
        for(int i=0;i<1000;i++){
            dfs(i,Achieved,G);
        }
        int count = 0;
        for(int i=1;i<=H;i++){
            for(int j=1;j<=W;j++){
                if(!Achieved[i*1000+j]){
                    count++;
                }
            }
        }
        sb.Append(count+"\n");
    }
    void dfs(int v,bool[] used,List<int>[] G){
        if(used[v]){
            return;
        }
        used[v] = true;
        for(int i=0;i<G[v].Count;i++){
            int t = G[v][i];
            dfs(t,used,G);
        }
    }
}
class ReadData{
    string[] str;
    int counter;
    public ReadData(){
        counter = 0;
    }
    public string s(){
        if(counter == 0){
            str = Console.ReadLine().Split(' ');
            counter = str.Length;
        }
        counter--;
        return str[str.Length-counter-1];
    }
    public int i(){
        return int.Parse(s());
    }
    public long l(){
        return long.Parse(s());
    }
    public double d(){
        return double.Parse(s());
    }
    public int[] ia(int N){
        int[] ans = new int[N];
        for(int j=0;j<N;j++){
            ans[j] = i();
        }
        return ans;
    }
    public int[] ia(){
        str = Console.ReadLine().Split(' ');
        counter = 0;
        int[] ans = new int[str.Length];
        for(int j=0;j<str.Length;j++){
            ans[j] = int.Parse(str[j]);
        }
        return ans;
    }
    public long[] la(int N){
        long[] ans = new long[N];
        for(int j=0;j<N;j++){
            ans[j] = l();
        }
        return ans;
    }
    public long[] la(){
        str = Console.ReadLine().Split(' ');
        counter = 0;
        long[] ans = new long[str.Length];
        for(int j=0;j<str.Length;j++){
            ans[j] = long.Parse(str[j]);
        }
        return ans;
    }
    public double[] da(int N){
        double[] ans = new double[N];
        for(int j=0;j<N;j++){
            ans[j] = d();
        }
        return ans;
    }
    public double[] da(){
        str = Console.ReadLine().Split(' ');
        counter = 0;
        double[] ans = new double[str.Length];
        for(int j=0;j<str.Length;j++){
            ans[j] = double.Parse(str[j]);
        }
        return ans;
    }
    public List<int>[] g(int N,int[] f,int[] t){
        List<int>[] ans = new List<int>[N];
        for(int j=0;j<N;j++){
            ans[j] = new List<int>();
        }
        for(int j=0;j<f.Length;j++){
            ans[f[j]].Add(t[j]);
            ans[t[j]].Add(f[j]);
        }
        return ans;
    }
    public List<int>[] g(int N,int M){
        List<int>[] ans = new List<int>[N];
        for(int j=0;j<N;j++){
            ans[j] = new List<int>();
        }
        for(int j=0;j<M;j++){
            int f = i()-1;
            int t = i()-1;
            ans[f].Add(t);
            ans[t].Add(f);
        }
        return ans;
    }
    public List<int>[] g(){
        int N = i();
        int M = i();
        List<int>[] ans = new List<int>[N];
        for(int j=0;j<N;j++){
            ans[j] = new List<int>();
        }
        for(int j=0;j<M;j++){
            int f = i()-1;
            int t = i()-1;
            ans[f].Add(t);
            ans[t].Add(f);
        }
        return ans;
    }
}
public static class Define{
    public const long mod = 1000000007;
}
public static class Debug{
    public static void Print(double[,,] k){
        for(int i=0;i<k.GetLength(0);i++){
            for(int j=0;j<k.GetLength(1);j++){
                for(int l=0;l<k.GetLength(2);l++){
                    Console.Write(k[i,j,l]+" ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
    }
    public static void Print(double[,] k){
        for(int i=0;i<k.GetLength(0);i++){
            for(int j=0;j<k.GetLength(1);j++){
                Console.Write(k[i,j]+" ");
            }
            Console.WriteLine();
        }
    }
    public static void Print(double[] k){
        for(int i=0;i<k.Length;i++){
            Console.WriteLine(k[i]);
        }
    }
    public static void Print(long[,,] k){
        for(int i=0;i<k.GetLength(0);i++){
            for(int j=0;j<k.GetLength(1);j++){
                for(int l=0;l<k.GetLength(2);l++){
                    Console.Write(k[i,j,l]+" ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
    }
    public static void Print(long[,] k){
        for(int i=0;i<k.GetLength(0);i++){
            for(int j=0;j<k.GetLength(1);j++){
                Console.Write(k[i,j]+" ");
            }
            Console.WriteLine();
        }
    }
    public static void Print(long[] k){
        for(int i=0;i<k.Length;i++){
            Console.WriteLine(k[i]);
        }
    }
    public static void Print(int[,,] k){
        for(int i=0;i<k.GetLength(0);i++){
            for(int j=0;j<k.GetLength(1);j++){
                for(int l=0;l<k.GetLength(2);l++){
                    Console.Write(k[i,j,l]+" ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
    }
    public static void Print(int[,] k){
        for(int i=0;i<k.GetLength(0);i++){
            for(int j=0;j<k.GetLength(1);j++){
                Console.Write(k[i,j]+" ");
            }
            Console.WriteLine();
        }
    }
    public static void Print(int[] k){
        for(int i=0;i<k.Length;i++){
            Console.WriteLine(k[i]);
        }
    }
}

Submission Info

Submission Time
Task D - うほょじご
User leign
Language C# (Mono 4.6.2.0)
Score 400
Code Size 7410 Byte
Status
Exec Time 471 ms
Memory 97004 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt
All 400 / 400 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt 446 ms 97004 KB
02.txt 452 ms 94956 KB
03.txt 450 ms 92908 KB
04.txt 444 ms 94956 KB
05.txt 443 ms 92908 KB
06.txt 441 ms 90860 KB
07.txt 456 ms 90860 KB
08.txt 463 ms 92908 KB
09.txt 471 ms 97004 KB
10.txt 451 ms 92908 KB
11.txt 450 ms 92908 KB
12.txt 450 ms 92908 KB
13.txt 452 ms 90988 KB
14.txt 453 ms 92908 KB
15.txt 453 ms 92908 KB
16.txt 454 ms 90860 KB
s1.txt 450 ms 90988 KB
s2.txt 451 ms 94956 KB
s3.txt 452 ms 97004 KB