Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class ProblemLover3
- {
- static void Main()
- {
- // filling matrix
- int[] rowCol = Console.ReadLine()
- .Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(r => int.Parse(r))
- .ToArray();
- int x = rowCol[0];
- int y = rowCol[1];
- int[,] matrix = new int[x, y];
- int p = 0;
- int k = 3;
- matrix[rowCol[0] - 1, 0] = p;
- for (int i = x - 1; i >= 0; i--)
- {
- for (int j = 0; j < y; j++)
- {
- matrix[i, j] = p;
- p += 3;
- }
- p = k;
- k += 3;
- }
- // reading instruction lines
- int n = int.Parse(Console.ReadLine());
- List<string> lines = new List<string>();
- for (int i = 0; i < n; i++)
- {
- lines.Add(Console.ReadLine());
- }
- // solution
- int currentX = x - 1;
- int currentY = 0;
- int sum = 0;
- for (int i = 0; i < n; i++)
- {
- string direction = lines[i].Substring(0, 2);
- for (int j = 0; j < (lines[i][lines[i].Length - 1] - '0'); j++)
- {
- sum += matrix[currentX, currentY];
- matrix[currentX, currentY] = 0;
- if (direction == "RU" || direction == "UR")
- {
- currentX--;
- currentY++;
- if (currentX < 0)
- {
- currentX = 0;
- }
- if (currentY >= y)
- {
- currentY = y - 1;
- }
- }
- if (direction == "LU" || direction == "UL")
- {
- currentX--;
- currentY--;
- if (currentX < 0)
- {
- currentX = 0;
- }
- if (currentY < 0)
- {
- currentY = 0;
- }
- }
- if (direction == "DL" || direction == "LD")
- {
- currentX++;
- currentY++;
- if (currentX >= x)
- {
- currentX = x - 1;
- }
- if (currentY >= y)
- {
- currentY = y - 1;
- }
- }
- if (direction == "RD" || direction == "DR")
- {
- currentX++;
- currentY--;
- if (currentX >= x)
- {
- currentX = x - 1;
- }
- {
- currentY = 0;
- }
- }
- }
- }
- Console.WriteLine(sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement