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.Diagnostics;
- namespace ForDZ
- {
- class Solution
- {
- enum direct { None = 0, top, right, bottom, left }
- struct info
- {
- public int count;
- public direct direction;
- }
- private int n, m;
- private List<StringBuilder> a;
- private info check_info;
- public Solution(int n, int m, string[] s)
- {
- a = new List<StringBuilder>();
- this.n = n;
- this.m = m;
- for (int i = 0; i < n; i++) a.Add(new StringBuilder(s[i]));
- }
- public int Processing()
- {
- int res = 0;
- while (can_continue())
- {
- check_info = check_field();
- delete();
- res += (check_info.count * check_info.count);
- }
- return res;
- }
- private int check_left()
- {
- int c = 0;
- for (int i = 0; i < n; i++) if (a[i][0] == '*') c++;
- return c;
- }
- private int check_right()
- {
- int c = 0;
- for (int i = 0; i < n; i++) if (a[i][a[i].Length - 1] == '*') c++;
- return c;
- }
- private int check_top()
- {
- int c = 0;
- for (int i = 0; i < a[0].Length; i++) if (a[0][i] == '*') c++;
- return c;
- }
- private int check_bottom()
- {
- int c = 0;
- for (int i = 0; i < a[0].Length; i++) if (a[a.Count - 1][i] == '*') c++;
- return c;
- }
- private info check_field()
- {
- int score = 0;
- direct dir = direct.None;
- int t;
- t = check_top();
- if (t > score)
- {
- score = t;
- dir = direct.top;
- }
- t = check_left();
- if (t > score)
- {
- score = t;
- dir = direct.left;
- }
- t = check_bottom();
- if (t > score)
- {
- score = t;
- dir = direct.bottom;
- }
- t = check_right();
- if (t > score)
- {
- score = t;
- dir = direct.right;
- }
- info res;
- res.count = score;
- res.direction = dir;
- return res;
- }
- private bool can_continue()
- {
- foreach (StringBuilder i in a)
- {
- if (i.Length > 0) return true;
- }
- return false;
- }
- private void delete_top()
- {
- a.RemoveAt(0);
- n--;
- }
- private void delete_bottom()
- {
- a.RemoveAt(a.Count - 1);
- n--;
- }
- private void delete_left()
- {
- for (int i = 0; i < n; i++) a[i].Remove(0, 1);
- m--;
- }
- private void delete_right()
- {
- for (int i = 0; i < n; i++) a[i].Remove(a[i].Length - 1, 1);
- m--;
- }
- private void delete()
- {
- switch (check_info.direction)
- {
- case direct.None: return;
- case direct.top: delete_top(); return;
- case direct.left: delete_left(); return;
- case direct.bottom: delete_bottom(); return;
- case direct.right: delete_right(); return;
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- int[] input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
- string[] s = new string[input[0]];
- for (int i = 0; i < input[0]; i++) s[i] = Console.ReadLine();
- Solution eto = new Solution(input[0], input[1], s);
- Console.WriteLine(eto.Processing());
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement