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.Text;
- using System.Threading.Tasks;
- namespace _3rdProblem
- {
- class Program
- {
- static void Main(string[] args)
- {
- string line = Console.ReadLine();
- string[] array = line.Split(' ');
- int r = int.Parse(array[0]);
- int c = int.Parse(array[1]);
- int[,] matrix = new int[r, c];
- int num = 0;
- for (int i = r - 1; i >= 0; i--)
- {
- for (int j = 0; j < c; j++)
- {
- matrix [i,j] = num;
- num += 3;
- }
- num = matrix[i, 1];
- }
- //for (int i = 0; i < r; i++)
- //{
- // for (int j = 0; j < c; j++)
- // {
- // if (j != c - 1)
- // {
- // Console.Write(matrix[i, j] + " ");
- // }
- // else
- // {
- // Console.Write(matrix[i, j]);
- // }
- // }
- // Console.WriteLine();
- //}
- int iterations = int.Parse(Console.ReadLine());
- string[] arr = new string[2];
- string command;
- int moves;
- int sum = 0;
- int startRow = r - 1;
- int startCol = 0;
- List <string> items = new List<string>();
- string checkItem;
- for (int ii = 0; ii < iterations; ii++)
- {
- line = Console.ReadLine();
- arr = line.Split(' ');
- command = arr[0];
- moves = int.Parse(arr[1]);
- if (command == "UR" || command == "RU")
- {
- for (int i = 0; i < moves; i++)
- {
- if (startCol < 0 || startCol >= c || startRow < 0 || startRow >= r)
- {
- startRow++;
- startCol--;
- break;
- }
- checkItem = startRow.ToString() + startCol.ToString();
- if (items.Contains(checkItem) == false)
- {
- sum += matrix[startRow, startCol];
- items.Add(checkItem);
- }
- if (i == moves - 1)
- {
- break;
- }
- startRow--;
- startCol++;
- }
- }
- if (command == "RD" || command == "DR")
- {
- for (int i = 0; i < moves; i++)
- {
- if (startCol < 0 || startCol >= c || startRow < 0 || startRow >= r)
- {
- startRow--;
- startCol--;
- break;
- }
- checkItem = startRow.ToString() + startCol.ToString();
- if (items.Contains(checkItem) == false)
- {
- sum += matrix[startRow, startCol];
- items.Add(checkItem);
- }
- if (i == moves - 1)
- {
- break;
- }
- startRow++;
- startCol++;
- }
- }
- if (command == "DL" || command == "LD")
- {
- for (int i = 0; i < moves; i++)
- {
- if (startCol < 0 || startCol >= c || startRow < 0 || startRow >= r)
- {
- startRow--;
- startCol++;
- break;
- }
- checkItem = startRow.ToString() + startCol.ToString();
- if (items.Contains(checkItem) == false)
- {
- sum += matrix[startRow, startCol];
- items.Add(checkItem);
- }
- if (i == moves - 1)
- {
- break;
- }
- startRow++;
- startCol--;
- }
- }
- if (command == "UL" || command == "LU")
- {
- for (int i = 0; i < moves; i++)
- {
- if (startCol < 0 || startCol >= c || startRow < 0 || startRow >= r)
- {
- startRow++;
- startCol++;
- break;
- }
- checkItem = startRow.ToString() + startCol.ToString();
- if (items.Contains(checkItem) == false)
- {
- sum += matrix[startRow, startCol];
- items.Add(checkItem);
- }
- if (i == moves - 1)
- {
- break;
- }
- startRow--;
- startCol--;
- }
- }
- }
- Console.WriteLine(sum);
- Console.Read();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement