東大卒のお金やりくり奮闘記~株、家計、趣味、経済~

東大卒でメーカー勤務の私がセミリタイアするために投資などを頑張っていこうという趣旨で始めたブログです。既婚男性です。株、家計、趣味、経済の話をメインにゆるゆる話します。

ABC182で書いたコード

using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace debug
{
    class main
    {
        static void Main(string args)
        {
            //問題クラスを展開
            ProgramE a = new ProgramE();
            a.main();//実行する

        }

    }
    //ABC182
    class ProgramA
    {
        public void main()
        {
            //入力
            string s = Console.ReadLine().Split();
            //2A+100-Bが増やせる数
            Console.WriteLine(2 * int.Parse(s[0]) + 100 - int.Parse(s[1]));

        }
    }

    class ProgramB
    {
        public void main()
        {
            //入力
            int N = int.Parse(Console.ReadLine());
            string a = Console.ReadLine().Split();

            int max = 0;
            int ans = 0;
            //1000までやってみる。N=100なので間に合う
            for (int i = 2i <= 1000i++)
            {
                int count = 0;
                for(int j = 0;j < N;j++)
                {
                    if (int.Parse(a[j]) % i == 0)
                        count++;
                }

                if (max < count)
                {
                    ans = i;
                    max = count;
                }
            }

            //答を出力
            Console.WriteLine(ans);



        }
    }

    class ProgramC
    {
        public void main()
        {

            //入力
            string s = Console.ReadLine();

            int c = new int[3];
            int sum = 0;
            //3で割ったあまりを分ける
            for (int i = 0i < s.Lengthi++)
            {
                c[(s[i] - '0') % 3]++;
                sum += (s[i] - '0');//そうわをだす
            }

            //出せないときを出す
            if (s.Length <= 2)
                if (c[1] == s.Length || c[2] == s.Length)
                {
                    Console.WriteLine(-1);
                    return;
                }


            //総和のあまりの数で場合分け
            if (sum % 3 == 0)
                Console.WriteLine(0);
            else if (sum % 3 == 1)
            {
                if (c[1] > 0)
                    Console.WriteLine(1);
                else
                    Console.WriteLine(2);
            }
            else
            {
                if (c[2] > 0)
                    Console.WriteLine(1);
                else
                    Console.WriteLine(2);
            }









        }

    }


    class ProgramD
    {
        public void main()
        {
            //入力
            long n = long.Parse(Console.ReadLine());
            string s = Console.ReadLine().Split();

            long c = new long[n];

            //累積和で記録
            c[0] = long.Parse(s[0]);
            for (int i = 1i < ni++)
                c[i] = c[i - 1] + long.Parse(s[i]);

            //累積和で判断
            long max = 0;
            long sum = 0;
            long sonomax = 0;
            for(int i = 0;i < n;i++)
            {
                //初項処理
                if (i == 0)
                {
                    max = Math.Max(maxc[i]);
                    sum += c[i];
                    sonomax = c[i];
                    continue;
                }

                //その時までの最大値を見てみる
                sonomax = Math.Max(sonomaxc[i]);
                //途中でありうる最大を加味
                max = Math.Max(maxsonomax + sum);

                //最後までの計算を足す
                sum += c[i];
            }

            //答
            Console.WriteLine(max);

        }


    }

    class ProgramE
    {
        public void main()
        {
            //入力
            string s = Console.ReadLine().Split(' ');
            long H = long.Parse(s[0]);
            long W = long.Parse(s[1]);
            long N = long.Parse(s[2]);
            long M = long.Parse(s[3]);

            int[,] maze = new int[HW];
            int[,] maze2 = new int[HW];
            int x = new int[N];
            int y = new int[N];

            //光源を記録
            for(int i = 0i < N;i++)
            {
                string t = Console.ReadLine().Split();
                x[i] = int.Parse(t[0]) - 1;
                y[i] = int.Parse(t[1]) - 1;
            }
            
            //ブロックをカウントする
            for (int i = 0i < M;i++)
            {
                string[] t = Console.ReadLine().Split();
                maze[int.Parse(t[0]) - 1int.Parse(t[1]) - 1] = 2;
                maze2[int.Parse(t[0]) - 1int.Parse(t[1]) - 1] = 2;

            }

            //光源ごとに判定する
            for (int i = 0i < Ni++)
            {
                //すでに記録済みなら飛ばす
                if (maze[x[i], y[i]] == 1)
                    continue;

                //横方向を確認する
                for (int j = x[i]; j >= 0j--)
                {
                    if (maze[jy[i]] == 2)
                        break;
                    maze[jy[i]] = 1;
                }

                for (int j = x[i] + 1j < Hj++)
                {
                    if (maze[jy[i]] == 2)
                        break;

                    maze[jy[i]] = 1;
                }

            }

            
            for (int i = 0i < Ni++)
            {
                //すでに記録済みなら飛ばす
                if (maze2[x[i], y[i]] == 1)
                    continue;

                
                //縦方向を見る
                for (int j = y[i]; j >= 0j--)
                {
                    if (maze2[x[i], j] == 2)
                        break;

                    maze2[x[i], j] = 1;
                }

                for (int j = y[i] + 1j < Wj++)
                {
                    if (maze2[x[i], j] == 2)
                        break;
                    maze2[x[i], j] = 1;
                }
            }

            //1のところが光る
            long ans = 0;
            for (int i = 0i < Hi++)
                for (int j = 0j < Wj++)
                {
                    if (maze[ij] == 1|| maze2[ij] == 1)
                        ans++;
                }

            //答え出力
            Console.WriteLine(ans);



        }
    }

}