結果
| 問題 |
No.208 王将
|
| コンテスト | |
| ユーザー |
nuwasogi
|
| 提出日時 | 2015-11-23 00:34:00 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 28 ms / 1,000 ms |
| コード長 | 2,755 bytes |
| コンパイル時間 | 973 ms |
| コンパイル使用メモリ | 114,148 KB |
| 実行使用メモリ | 19,328 KB |
| 最終ジャッジ日時 | 2024-10-09 16:28:46 |
| 合計ジャッジ時間 | 2,406 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 23 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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(); }
}
}
nuwasogi