Submission #1349102
Source Code Expand
using System; using System.Linq; using System.Collections.Generic; public class Program { public static void Main() { var nlt = Console.ReadLine().Split() .Select(x => long.Parse(x)) .ToArray(); var n = (int)nlt[0]; var l = nlt[1]; var t = nlt[2]; var antsQuery = from i in Enumerable.Range(0, n) let ant = Console.ReadLine().Split() .Select(x => long.Parse(x)) .ToArray() select new { pos = ant[0], dir = (int)ant[1] }; var ants = antsQuery.ToArray(); t %= l; var xs = ants.Select(x => x.pos).ToArray(); var ws = ants.Select(x => x.dir).ToArray(); var signs = ws.Select(w => w * 2 - 3).ToArray(); // clockwise: -1, counterclockwise: 1 var swapping = Enumerable.Range(0, n) .Where(i => ws[i] != ws[0]) .Count(i => PositiveMod((xs[0] - xs[i]) * signs[0], l) <= 2 * t); for (int i = 0; i < n; ++i) { xs[i] = PositiveMod(xs[i] - t % l * signs[i], l); } Array.Sort(xs); var ant = xs[(n * 2 - swapping * (int)signs[0]) % n]; var o = Array.BinarySearch(xs, ant); var finalPositions = Enumerable.Concat(xs, xs).Skip(o).Take(n); Console.WriteLine(string.Join("\n", finalPositions)); } static long PositiveMod(long n, long mod) => n >= 0 ? n % mod : (n + mod) % mod; }
Submission Info
Submission Time | |
---|---|
Task | C - Ants on a Circle |
User | nitumeta339 |
Language | C# (Mono 4.6.2.0) |
Score | 0 |
Code Size | 1512 Byte |
Status | CE |
Compile Error
./Main.cs(36,13): error CS0136: A local variable named `ant' cannot be declared in this scope because it would give a different meaning to `ant', which is already used in a `child' scope to denote something else