結果
問題 | No.48 ロボットの操縦 |
ユーザー |
![]() |
提出日時 | 2016-10-04 10:15:04 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,354 bytes |
コンパイル時間 | 1,215 ms |
コンパイル使用メモリ | 115,952 KB |
実行使用メモリ | 26,108 KB |
最終ジャッジ日時 | 2024-11-21 15:33:47 |
合計ジャッジ時間 | 9,231 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 TLE * 1 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;using System.Diagnostics;namespace CodeIq{internal class Program{/// <summary>/// 太郎君はロボットを遠隔で操縦している。////// このロボットは現在(0,0)の座標に立っていて北の方向を向いている。/// 太郎君はいまこのロボットを(X,Y)の座標に移動させたいと思っている。////// ロボットに出来る命令は、1回につき以下のうちいずれかの命令を選んで指示することができる。/// ・時計回りに、90∘ その場で向き(進行方向)を変える。/// ・反時計回りに、90∘ その場で向き(進行方向)を変える。/// ・向いている方向に K距離だけ前進する。Kは、(1≤K≤L) の範囲で、命令のたびに指定することができる。/// </summary>private static void Main(){// パラメータ取得var line1 = Console.ReadLine();var line2 = Console.ReadLine();var line3 = Console.ReadLine();//var line1 = "0";//var line2 = "-1";//var line3 = "1000000000";if( string.IsNullOrEmpty( line1 ) )return;if( string.IsNullOrEmpty( line2 ) )return;if( string.IsNullOrEmpty( line3 ) )return;var x = int.Parse( line1 );var y = int.Parse( line2 );var l = int.Parse( line3 );var nowX = 0;var nowY = 0;var nowDir = Direction.North;var orderCount = 0;var getRedirectCount = new Func<Direction, Direction, int>( ( dir, nextDir ) =>{if( dir == nextDir )return 0;else if( ( (int)dir % 2 == 0 ) != ( (int)nextDir % 2 == 0 ) )return 1;elsereturn 2;} );var getMoveCount = new Func<int, int, int>( ( pos, nextPos ) =>{var addValue = ( pos < nextPos ) ? 1 : -1;var moveCount = 0;while( pos != nextPos ){moveCount++;if( Math.Abs( nextPos - pos ) > l )pos += addValue * l;elsepos = nextPos;}return moveCount;} );// 向き変更を最小限に抑える順番// ①↑ ②(←、→) ③↓var nextDirections = new Direction[3];nextDirections[0] = Direction.North;nextDirections[1] = ( nowX < x ) ? Direction.West : Direction.East;nextDirections[2] = Direction.South;foreach( var nextDir in nextDirections ){var isX = ( (int)nextDir % 2 == 0 );var isPositive = ( nextDir > 0 );var nowPos = isX ? nowX : nowY;var nextPos = isX ? x : y;// 移動する必要がない場合は処理しないif( nowPos == nextPos )continue;// 対応する向きへの計算が不要の場合も処理しないif( isPositive && nowPos > nextPos )continue;if( !isPositive && nowPos < nextPos )continue;orderCount += getRedirectCount( nowDir, nextDir );nowDir = nextDir;orderCount += getMoveCount( nowPos, nextPos );if( isX )nowX = x;elsenowY = y;}Debug.Print( orderCount.ToString() );Console.WriteLine( orderCount );}/// <summary>/// 向きを表す列挙体<br />/// 奇数値の場合はY軸方向、偶数値の場合はX軸方向<br />/// 正数の場合は加算方向、負数値の場合は減算方向/// </summary>public enum Direction{North = 1,West = 2,South = -1,East = -2}}}