This Wednesday I have not participated in the CodeForces competition – I was either too tired on Wednesday or I had something better to do. 🙂 Anyhow, I have just taken a quick look at the first two problems of the competition and as usually happens when person solves the problems outside a competition I have managed to solve them unexpectedly quick. The second problem actually was solved in 4 minutes (coding, reading and submitting) and I was quite surprised for it. The first one was also solved rather fast 🙂 Let’s hope that on the next competition I would be having the same success as today 🙂
The idea is to find the maximum sequence of days, in which we do not get all enemies at school. At first it seemed rather easy, but then I realized that I need a quick way to make the numbers with which I am comparing. Thus, I have built the function CheckNumber(int enemies_count), with the idea to compare strings and not integers, because it would be faster this way and I would not go outside range. It was a trick that in the problem the maximum of enemies was not given, thus someone can put like 100 enemies, which would make even big integer overflow. Once, this was made, I simply wrote every result per day in a list and at the end I have displayed the maximum of this list. Literally nothing could have been wrong there.
In the second problem I really thought that something was wrong – it was unbelievably easy for a second one. You simply have to take the input, reverse it and write it. Probably the problem was tough, that you should realize this by reading the problem. But once you think about 30 seconds, you realize what they want from you.
Pretty much that is all. Here is the code of the first problem:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; class test_code_forces01 { static void Main() { string[] input = Console.ReadLine().Split(); int enemies_count = int.Parse(input[0]); int days_count = int.Parse(input[1]); List<int> results = new List<int>(); string number_max = CheckNumber(enemies_count); string current_string = ""; int biggest_sequence = 0; for (int i = 0; i < days_count; i++) { current_string = Console.ReadLine(); if (current_string.Equals(number_max,StringComparison.Ordinal)) { biggest_sequence = 0; } else { biggest_sequence++; } results.Add(biggest_sequence); } Console.WriteLine(results.Max()); } static string CheckNumber(int enemies_count) { string result = ""; for (int i = 0; i < enemies_count; i++) { result += "1"; } return result; } } |
Here is the code of the second one:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class test_code_forces02 { static void Main() { string input = Console.ReadLine(); Console.WriteLine(input+Reverse(input)); } public static string Reverse(string s) { char[] charArray = s.ToCharArray(); Array.Reverse(charArray); return new string(charArray); } } |
Here comes the code in GitHub.