Submission #668755


Source Code Expand

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

using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
	public Program() { }

	static void Main(string[] args)
	{
		new Program().prog();
	}
	Scanner cin;
	const int MOD = 1000000007;
	const int INF = int.MaxValue;
	const double EPS = 1e-7;

	int N = 30;

	void prog()
	{
		cin = new Scanner();

		int[,] a = new int[N, N];
		Pair pos = new Pair();
		int max = 0;
		for (int i = 0; i < N; i++)
		{
			for (int j = 0; j < N; j++)
			{
				a[i, j] = cin.nextInt();
				if (a[i, j] > max)
				{
					max = a[i, j];
					pos = new Pair(i, j);
				}
			}
		}
		int[,] d = new int[,] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };
		List<Pair> list = new List<Pair>();
		bool[,] visited = new bool[N, N];
		while (max > 0)
		{
			while (true)
			{
				// debug
				//Console.WriteLine("now: {0},{1}", pos.Key + 1, pos.Value + 1);
				
				// 経路に追加
				list.Add(pos);
				visited[pos.Key, pos.Value] = true;

				if (a[pos.Key, pos.Value] - 1 == 0) break;

				bool flag = false;

				// 普通に行けるところを探す
				for (int i = 0; i < 4; i++)
				{
					// 盤外チェック
					if (pos.Key + d[i, 0] < 0 || pos.Key + d[i, 0] >= N
						|| pos.Value + d[i, 1] < 0 || pos.Value + d[i, 1] >= N) continue;
					
					if (a[pos.Key + d[i, 0], pos.Value + d[i, 1]] == a[pos.Key, pos.Value] - 1)
					{
						// debug
						//Console.WriteLine("next: {0},{1}", pos.Key + d[i, 0] + 1, pos.Value + d[i, 1] + 1);
						pos = new Pair(pos.Key + d[i, 0], pos.Value + d[i, 1]);
						flag = true;
						break;
					}
				}
				// 行けるならそのまま行く
				if (flag)
				{
					continue;
				}
				// 普通に行けないなら、隣接する「より高いマス」を探す
				for (int i = 0; i < 4; i++)
				{
					// 盤外チェック
					if (pos.Key + d[i, 0] < 0 || pos.Key + d[i, 0] >= N
						|| pos.Value + d[i, 1] < 0 || pos.Value + d[i, 1] >= N) continue;
					if (visited[pos.Key + d[i, 0], pos.Value + d[i, 1]]) continue;

					// より高いところと隣接してたら
					if (a[pos.Key + d[i, 0], pos.Value + d[i, 1]] >= a[pos.Key, pos.Value])
					{
						// debug
						//Console.WriteLine("reset: {0},{1}", pos.Key + d[i, 0] + 1, pos.Value + d[i, 1] + 1);

						// 極高まで追跡
						Pair next = new Pair(pos.Key + d[i, 0], pos.Value + d[i, 1]);
						while (true)
						{
							// 極高でないフラグ
							bool flag2 = false;
							// 極高チェック
							for (int j = 0; j < 4; j++)
							{
								// 盤外チェック
								if (next.Key + d[j, 0] < 0 || next.Key + d[j, 0] >= N
									|| next.Value + d[j, 1] < 0 || next.Value + d[j, 1] >= N) continue;
								if (visited[next.Key + d[j, 0], next.Value + d[j, 1]]) continue;

								// 周囲により高いマスがあれば
								if (a[next.Key + d[j, 0], next.Value + d[j, 1]]
									> a[next.Key, next.Value])
								{
									next = new Pair(next.Key + d[j, 0], next.Value + d[j, 1]);
									flag2 = true;
									break; ;
								}
							}
							// 極高なら
							if (!flag2)
							{
								break;
							}
						}

						// そこを始点に
						pos = next;
						// リストをクリア
						list.Clear();
						flag = true;
						break;
					}
				}
				// より高い極高マスも無かったら
				if (!flag)
				{
					break;
				}
			}

			// 経路確定・出力
			//Console.WriteLine(list.Count);
			for (int i = 0; i < list.Count; i++)
			{
				a[list[i].Key, list[i].Value]--;
				Console.WriteLine("{0} {1}", list[i].Key + 1, list[i].Value + 1);
			}

			// visited初期化
			for (int i = 0; i < N; i++)
			{
				for (int j = 0; j < N; j++)
				{
					visited[i, j] = false;
				}
			}

			// リストを空にする
			list.Clear();

			// 最大値を探す
			max = 0;
			for (int i = 0; i < N; i++)
			{
				for (int j = 0; j < N; j++)
				{
					if (a[i, j] > max)
					{
						max = a[i, j];
						pos = new Pair(i, j);
					}
				}
			}
			//print(a);
		}
	}
	void print(int[,] a)
	{
		Console.WriteLine();
		for (int i = 0; i < N; i++)
		{
			for (int j = 0; j < N; j++)
			{
				Console.Write("{0:00}", a[i, j]);
			}
			Console.WriteLine();
		}
		Console.WriteLine();
	}
}

class Scanner
{
	string[] s;
	int i;

	char[] cs = new char[] { ' ' };

	public Scanner()
	{
		s = new string[0];
		i = 0;
	}

	public string next()
	{
		if (i < s.Length) return s[i++];
		string st = Console.ReadLine();
		while (st == "") st = Console.ReadLine();
		s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
		i = 0;
		return next();
	}

	public int nextInt()
	{
		return int.Parse(next());
	}

	public long nextLong()
	{
		return long.Parse(next());
	}

	public double nextDouble()
	{
		return double.Parse(next());
	}

}

Submission Info

Submission Time
Task A - 高橋君の山崩しゲーム
User furuya1223
Language C# (Mono 4.6.2.0)
Score 873615
Code Size 5089 Byte
Status AC
Exec Time 788 ms
Memory 7376 KB

Judge Result

Set Name test_01 test_02 test_03 test_04 test_05 test_06 test_07 test_08 test_09 test_10
Score / Max Score 87440 / 100000 87235 / 100000 87338 / 100000 87275 / 100000 87354 / 100000 86936 / 100000 88076 / 100000 87075 / 100000 87613 / 100000 87273 / 100000
Status
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
Set Name Test Cases
test_01 subtask_01_01.txt
test_02 subtask_01_02.txt
test_03 subtask_01_03.txt
test_04 subtask_01_04.txt
test_05 subtask_01_05.txt
test_06 subtask_01_06.txt
test_07 subtask_01_07.txt
test_08 subtask_01_08.txt
test_09 subtask_01_09.txt
test_10 subtask_01_10.txt
Case Name Status Exec Time Memory
subtask_01_01.txt AC 713 ms 7376 KB
subtask_01_02.txt AC 772 ms 7248 KB
subtask_01_03.txt AC 705 ms 7248 KB
subtask_01_04.txt AC 772 ms 7248 KB
subtask_01_05.txt AC 732 ms 7248 KB
subtask_01_06.txt AC 771 ms 7248 KB
subtask_01_07.txt AC 788 ms 7248 KB
subtask_01_08.txt AC 753 ms 7248 KB
subtask_01_09.txt AC 716 ms 7248 KB
subtask_01_10.txt AC 717 ms 7248 KB