Submission #2995505


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();
        bool[,] Map = new bool[H,W];
        for(int i=0;i<H;i++){
            string S = re.s();
            for(int j=0;j<W;j++){
                Map[i,j] = S[j] == '.';
            }
        }
        int[,] U = new int[H,W];
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(Map[i,j]){
                    if(i != 0){
                        U[i,j] = U[i-1,j]+1;
                    }
                    else{
                        U[i,j] = 1;
                    }
                }
            }
        }
        int[,] D = new int[H,W];
        for(int i=H-1;i>=0;i--){
            for(int j=0;j<W;j++){
                if(Map[i,j]){
                    if(i != H-1){
                        D[i,j] = D[i+1,j]+1;
                    }
                    else{
                        D[i,j] = 1;
                    }
                }
            }
        }
        int[,] L = new int[H,W];
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(Map[i,j]){
                    if(j != 0){
                        L[i,j] = L[i,j-1]+1;
                    }
                    else{
                        L[i,j] = 1;
                    }
                }
            }
        }
        int[,] R = new int[H,W];
        for(int i=0;i<H;i++){
            for(int j=W-1;j>=0;j--){
                if(Map[i,j]){
                    if(j != W-1){
                        R[i,j] = R[i,j+1]+1;
                    }
                    else{
                        R[i,j] = 1;
                    }
                }
            }
        }
        long count = 0;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(Map[i,j]){
                    count += (L[i,j]-1)*(U[i,j]-1);
                    count += (L[i,j]-1)*(D[i,j]-1);
                    count += (R[i,j]-1)*(U[i,j]-1);
                    count += (R[i,j]-1)*(D[i,j]-1);
                }
            }
        }
        sb.Append(count+"\n");
    }
}
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 C - 右折
User leign
Language C# (Mono 4.6.2.0)
Score 400
Code Size 7721 Byte
Status
Exec Time 345 ms
Memory 81352 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, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt 345 ms 81344 KB
02.txt 335 ms 81352 KB
03.txt 340 ms 79312 KB
04.txt 338 ms 79192 KB
05.txt 314 ms 79288 KB
06.txt 321 ms 81344 KB
07.txt 315 ms 79304 KB
08.txt 316 ms 81232 KB
09.txt 304 ms 79192 KB
10.txt 303 ms 79288 KB
11.txt 305 ms 81344 KB
12.txt 305 ms 79304 KB
13.txt 187 ms 79312 KB
14.txt 187 ms 81240 KB
15.txt 307 ms 79416 KB
16.txt 304 ms 81344 KB
17.txt 129 ms 28884 KB
18.txt 128 ms 28884 KB
19.txt 226 ms 81240 KB
20.txt 228 ms 79288 KB
21.txt 316 ms 81344 KB
22.txt 314 ms 81352 KB
23.txt 316 ms 79184 KB
24.txt 314 ms 81240 KB
25.txt 306 ms 81336 KB
26.txt 308 ms 81344 KB
27.txt 309 ms 79304 KB
28.txt 306 ms 81232 KB
29.txt 21 ms 11092 KB
30.txt 21 ms 11092 KB
31.txt 21 ms 11092 KB
32.txt 21 ms 9044 KB
33.txt 22 ms 11092 KB
34.txt 21 ms 9044 KB
35.txt 22 ms 11092 KB
36.txt 21 ms 9044 KB
s1.txt 21 ms 9044 KB
s2.txt 21 ms 11092 KB
s3.txt 21 ms 11092 KB