Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- /*******
- * Read input from Console
- * Use Console.WriteLine to output your result.
- * Use:
- * Utils.LocalPrint( variable);
- * to display simple variables in a dedicated area.
- *
- * Use:
- *
- Utils.LocalPrintArray( collection)
- * to display collections in a dedicated area.
- * ***/
- namespace CSharpContestProject
- {
- public class Program
- {
- static void Main(string[] args)
- {
- string line;
- var input = new List<string>();
- while ((line = Console.ReadLine()) != null)
- {
- input.Add(line);
- }
- new Problem(input).Solution();
- }
- }
- public class Problem
- {
- private char[][] grid;
- private int N;
- public Problem(List<string> input)
- {
- N = int.Parse(input.First());
- grid = input.Skip(1).Select(l => l.ToArray()).ToArray();
- }
- public void Solution()
- {
- var doorCount = grid.Select(l => l.Count(c => c == 'X')).Sum();
- var travelCount = 0;
- while(doorCount > 0)
- {
- var minColumn = 0;
- foreach (var row in Enumerable.Range(0, N))
- foreach (var column in Enumerable.Range(minColumn, N - minColumn))
- if (grid[row][column] == 'X')
- {
- grid[row][column] = '.';
- doorCount--;
- minColumn = column;
- }
- travelCount++;
- }
- Console.WriteLine(travelCount);
- }
- }
- }
Add Comment
Please, Sign In to add comment