ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1008. Image Encoding

Getting WA#1 with my code C#
Posted by nokkie 25 Jun 2019 06:02
using System;
using System.Linq;
using System.Collections.Generic;

public class Program
{
static void Main(string[] args)
{
int maxX = 0;
int maxY = 0;
int[,] str = new int[n,2];
for (int i = 0; i < n; i++)
{
str[i, 0] = int.Parse(s[0]);
str[i, 1] = int.Parse(s[1]);
if (str[i,0] > maxX) maxX = str[i,0];
if (str[i,1] > maxY) maxY = str[i,1];
}
bool[,] ans = new bool[maxX+2, maxY+2];
for (int i = 0; i < n; i++)
ans[str[i,0],str[i,1]]= true;

List<string> pool = new List<string>();
pool.Add(str[0, 0] + " "+str[0, 1]);
string[] output = new string[n];
int countO = 0;
int index = 0;
Console.WriteLine(pool.ElementAt(0));
while (index<pool.Count)
{
string[] point = pool.ElementAt(index).Split(' ');
int x = int.Parse(point[0]);
int y = int.Parse(point[1]);
ans[x, y] = false;
string search = "";
if (ans[x + 1, y]) { search += "R"; pool.Add((x + 1) + " " + y); ans[x+1, y] = false; }
if (ans[x, y + 1]) { search += "T"; pool.Add(x + " " + (y+1)); ans[x, y+1] = false; }
if (ans[x, y - 1]) { search += "B"; pool.Add(x + " " + (y-1)); ans[x, y-1] = false; }
output[countO] = search;
countO++;

//Console.WriteLine("in {0}",pool.Count);
index++;
}
for (int i = 0; i < n; i++)
{
Console.Write(output[i]);
if (i < n - 1) Console.WriteLine(",");
else Console.WriteLine(".");
}
}
}