| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using System;
- namespace D11._1
- {
- class Program
- {
- static void Main(string[] args)
- {
- if (args.Length == 0) return;
- int serial = int.Parse(args[0]);
- const int length = 300;
- var grid = new int[length, length];
- for (int x = 1; x <= length; ++x)
- {
- for (int y = 1; y <= length; ++y)
- {
- int id = (x + 10);
- int n = (id * y + serial) * id;
- int c = (n / 100) % 10;
- grid[x - 1, y - 1] = c - 5;
- }
- }
- int maxTotal = 0;
- (int x, int y)? maxCoordinates = null;
- for (int x = 1; x <= length - 2; ++x)
- {
- for (int y = 1; y <= length - 2; ++y)
- {
- int total = 0;
- for (int j = 0; j < 3; ++j)
- for (int i = 0; i < 3; ++i)
- total += grid[x - 1 + i, y - 1 + j];
- if (total > maxTotal)
- {
- maxTotal = total;
- maxCoordinates = (x, y);
- }
- }
- }
- Console.WriteLine($"The answer is : ({maxCoordinates.Value.x},{maxCoordinates.Value.y})");
- }
- }
- }
|