Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Numerics;
- using System.Threading.Tasks;
- namespace _03
- {
- class Program
- {
- static void Main(string[] args)
- {
- int r = int.Parse(Console.ReadLine());
- int c = int.Parse(Console.ReadLine());
- int n = int.Parse(Console.ReadLine());
- decimal[] commands = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => decimal.Parse(x)).ToArray();
- BigInteger sum = 0;
- BigInteger[,] matrix = new BigInteger[r, c];
- BigInteger power = 1;
- for (int row = r - 1; row >= 0; row--)
- {
- for (int col = 0; col < c; col++)
- {
- matrix[row, col] = (BigInteger)((BigInteger)Math.Pow(2, col) * power);
- }
- power = power * 2;
- }
- int peshoRow = r - 1;
- int peshoCol = 0;
- string direction = "";
- switch (direction)
- {
- case "up": peshoRow--;
- break;
- case "down": peshoRow++;
- break;
- case "left": peshoCol--;
- break;
- case "right": peshoCol++;
- break;
- }
- foreach (var command in commands)
- {
- int coeff = Math.Max(r, c);
- decimal targetRow = (ulong)(command / coeff);
- decimal targetCol = (ulong)(command % coeff);
- while (targetRow != peshoRow && peshoRow >= 0 && peshoRow < r && peshoCol < c && peshoCol >= 0)
- {
- if (targetRow < peshoRow) peshoRow--;//direction = "up";
- else if (targetRow > peshoRow) peshoRow++;//direction = "down";
- sum += matrix[peshoRow, peshoCol];
- matrix[peshoRow, peshoCol] = 0;
- }
- while (targetCol != peshoCol && peshoRow >= 0 && peshoRow < r && peshoCol < c && peshoCol >= 0)
- {
- if (targetCol < peshoCol) peshoCol--;
- else if (targetCol > peshoCol) peshoCol++;
- sum += matrix[peshoRow, peshoCol];
- matrix[peshoRow, peshoCol] = 0;
- }
- }
- Console.WriteLine(sum + 1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement