結果

問題 No.208 王将
ユーザー nuwasoginuwasogi
提出日時 2015-11-23 00:34:00
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 28 ms / 1,000 ms
コード長 2,755 bytes
コンパイル時間 1,217 ms
コンパイル使用メモリ 114,824 KB
実行使用メモリ 27,660 KB
最終ジャッジ日時 2024-04-17 22:46:01
合計ジャッジ時間 2,059 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
25,236 KB
testcase_01 AC 25 ms
27,152 KB
testcase_02 AC 23 ms
25,236 KB
testcase_03 AC 23 ms
25,136 KB
testcase_04 AC 24 ms
25,240 KB
testcase_05 AC 24 ms
25,236 KB
testcase_06 AC 26 ms
25,372 KB
testcase_07 AC 23 ms
25,244 KB
testcase_08 AC 23 ms
27,272 KB
testcase_09 AC 24 ms
25,008 KB
testcase_10 AC 23 ms
25,236 KB
testcase_11 AC 25 ms
25,260 KB
testcase_12 AC 24 ms
25,108 KB
testcase_13 AC 26 ms
27,660 KB
testcase_14 AC 23 ms
27,148 KB
testcase_15 AC 24 ms
25,132 KB
testcase_16 AC 25 ms
25,240 KB
testcase_17 AC 24 ms
23,348 KB
testcase_18 AC 23 ms
25,008 KB
testcase_19 AC 23 ms
27,148 KB
testcase_20 AC 23 ms
27,276 KB
testcase_21 AC 25 ms
25,108 KB
testcase_22 AC 23 ms
23,096 KB
testcase_23 AC 23 ms
27,400 KB
testcase_24 AC 24 ms
25,236 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Oushou_CS
{
    class Program
    {
        static void Main(string[] args)
        {
            Sol mysol = new Sol();
            mysol.Solve();
#if DEBUG
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
#endif
        }
    }

    class Sol
    {
        public void Solve()
        {
            int ans = ChebyshevDistance(0, 0, x, y);
            if(isObstacle(x,y,x2, y2))
            {
                ans++;
            }
            Console.WriteLine(ans.ToString());
        }

        int x, y, x2, y2;

        public Sol()
        {
            int[] xy = ria();
            x = xy[0];
            y = xy[1];
            int[] xy2 = ria();
            x2 = xy2[0];
            y2 = xy2[1];
        }

        static int ChebyshevDistance(int x1, int y1, int x2, int y2)
        {
            return Math.Max(Math.Abs(x1 - x2), Math.Abs(y1 - y2));
        }

        // 象限を返す(0があるときも返す)
        static int Quadrant(int x, int y)
        {
            if (x > 0)
            {
                if (y > 0)
                {
                    return 1;
                }
                else
                {
                    return 4;
                }
            }
            else
            {
                if (y > 0)
                {
                    return 2;
                }
                else
                {
                    return 3;
                }
            }
        }

        static bool isObstacle(int x, int y, int x2, int y2)
        {
            int q1 = Quadrant(x, y);
            if ((Math.Abs(x) == Math.Abs(y)) && (Math.Abs(x2) == Math.Abs(y2)) && (q1 == Quadrant(x2, y2)))
            {
                int t = x - x2;
                if (((q1 == 1 || q1 == 4) && t>0) || ((q1 == 2 || q1 == 3) && t<0))
                {
                    return true;
                }
            }
            return false;
        }

        static String rs() { return Console.ReadLine(); }
        static int ri() { return int.Parse(Console.ReadLine()); }
        static long rl() { return long.Parse(Console.ReadLine()); }
        static double rd() { return double.Parse(Console.ReadLine()); }
        static String[] rsa() { return Console.ReadLine().Split(' '); }
        static int[] ria() { return Console.ReadLine().Split(' ').Select(e => int.Parse(e)).ToArray(); }
        static long[] rla() { return Console.ReadLine().Split(' ').Select(e => long.Parse(e)).ToArray(); }
        static double[] rda() { return Console.ReadLine().Split(' ').Select(e => double.Parse(e)).ToArray(); }
    }
}
0