Beispiel #1
0
        static void Main(string[] args)
        {
            using (var prob = new CodeJamProblem("D:\\CodeJam\\test.in"))
            {
                var TestCount = prob.ReadLineInt32();

                int Count = 0;
                for (var i = 0; i < TestCount; i++)
                {
                    var Parts = prob.ReadParts();

                    BigInteger r;
                    BigInteger t;
                    BigInteger n = 0;

                    if (BigInteger.TryParse(Parts[0], out r) && BigInteger.TryParse(Parts[1], out t))
                    {
                        BigInteger S1 = 2 * r + 1;
                        BigInteger D  = (S1 - 2);
                        D = D * D + 8 * t;

                        var vSqrt = Sqrt1(D);

                        n = (-(S1 - 2) + Sqrt1(D)) / 4;
                    }
                    else
                    {
                        Count = -10000000;
                    }

                    prob.OutputCase(n);
                }
            }
        }
Beispiel #2
0
    static void Main(string[] args)
    {
        using (var prob = new CodeJamProblem('c', ProblemType.Large, 0))
        {
            int t = prob.ReadLineInt32();
            for (int cases = 0; cases < t; cases++)
            {
                int   n   = prob.ReadLineInt32();
                int   ans = 0;
                int[] f   = prob.ReadInt32Array();

                int min = 10000000;
                int sum = 0;
                foreach (int x in f)
                {
                    ans  = (ans ^ x);
                    sum += x;
                    if (min > x)
                    {
                        min = x;
                    }
                }
                if (ans != 0)
                {
                    prob.OutputCase("NO");
                }
                else
                {
                    prob.OutputCase(sum - min);
                }
            }
        }
    }
Beispiel #3
0
 static void Main(string[] args)
 {
     using (var prob = new CodeJamProblem('a', ProblemType.Large, 0))
     {
         int t = prob.ReadLineInt32();
         for (int cases = 0; cases < t; cases++)
         {
             string[] cur = prob.ReadParts();
             int      n   = int.Parse(cur[0]);
             for (int i = 0; i < n; i++)
             {
                 if (cur[2 * i + 1].Equals("O"))
                 {
                     cur[2 * i + 1] = "0";
                 }
                 else
                 {
                     cur[2 * i + 1] = "1";
                 }
             }
             int[] time = new int[2];
             int[] last = new int[2] {
                 1, 1
             };
             for (int i = 0; i < n; i++)
             {
                 int x = int.Parse(cur[2 * i + 1]);
                 int p = int.Parse(cur[2 * i + 2]);
                 time[x] += Math.Abs(p - last[x]) + 1;
                 if (time[x] < time[1 - x] + 1)
                 {
                     time[x] = time[1 - x] + 1;
                 }
                 last[x] = p;
             }
             prob.OutputCase(Math.Max(time[0], time[1]));
         }
     }
 }
Beispiel #4
0
    static void Main(string[] args)
    {
        using (var prob = new CodeJamProblem('d', ProblemType.Large, 0))
        {
            int t = prob.ReadLineInt32();
            for (int cases = 0; cases < t; cases++)
            {
                int   n   = prob.ReadLineInt32();
                int   ans = 0;
                int[] f   = prob.ReadInt32Array();

                for (int i = 0; i < n; i++)
                {
                    if (f[i] != i + 1)
                    {
                        ans++;
                    }
                }
                prob.OutputCase(ans.ToString() + ".000000");
            }
        }
    }
Beispiel #5
0
 static void Main(string[] args)
 {
     using (var prob = new CodeJamProblem('c', ProblemType.Large, 0))
     {
         int tcase = prob.ReadLineInt32();
         for (int cases = 0; cases < tcase; cases++)
         {
             long[] a = prob.ReadInt64Array();
             int    n = (int)a[0];
             l = a[1];
             h = a[2];
             List <long> x  = new List <long>();
             long[]      ff = prob.ReadInt64Array();
             for (int i = 0; i < n; i++)
             {
                 x.Add(ff[i]);
             }
             long[] f = x.Distinct().ToArray();
             Array.Sort(f);
             n = f.Length;
             long[] gcd   = new long[n];
             long[] lcd   = new long[n];
             int    start = 0;
             while (f[start] == 0 && start < n)
             {
                 start++;
             }
             lcd[start] = f[start];
             for (int i = start + 1; i < n; i++)
             {
                 if (lcd[i - 1] == -1)
                 {
                     lcd[i] = -1;
                 }
                 else
                 {
                     lcd[i] = clcd(lcd[i - 1], f[i]);
                 }
             }
             gcd[n - 1] = f[n - 1];
             for (int i = n - 2; i >= start; i--)
             {
                 gcd[i] = cgcd(f[i], gcd[i + 1]);
             }
             long ans = getMin(l, h, gcd[0]);
             for (int i = start; i < n - 1; i++)
             {
                 if (i < n - 2 && f[i] == f[i + 1])
                 {
                     continue;
                 }
                 if (lcd[i] == -1)
                 {
                     break;
                 }
                 if (gcd[i + 1] % lcd[i] != 0)
                 {
                     continue;
                 }
                 if (lcd[i] <= gcd[i + 1])
                 {
                     long tl   = (l + lcd[i] - 1) / lcd[i];
                     long th   = h / lcd[i];
                     long tans = getMin(tl, th, gcd[i + 1] / lcd[i]) * lcd[i];
                     if (tans >= 0 && (ans == -1 || ans > tans))
                     {
                         ans = tans;
                     }
                 }
             }
             if (lcd[n - 1] != -1)
             {
                 long ttans = (l + lcd[n - 1] - 1) / lcd[n - 1] * lcd[n - 1];
                 if (ttans <= h && (ans == -1 || ttans < ans))
                 {
                     ans = ttans;
                 }
             }
             if (ans == -1)
             {
                 prob.OutputCase("NO");
             }
             else
             {
                 prob.OutputCase(ans.ToString());
             }
         }
     }
 }
Beispiel #6
0
 static void Main(string[] args)
 {
     using (var prob = new CodeJamProblem('a', ProblemType.Large, 0))
     {
         int tcase = prob.ReadLineInt32();
         for (int cases = 0; cases < tcase; cases++)
         {
             int[]    a  = prob.ReadInt32Array();
             int      r  = a[0];
             int      c  = a[1];
             string[] ss = prob.ReadLines(r);
             char[,] s = new char[r, c];
             for (int i = 0; i < r; i++)
             {
                 for (int j = 0; j < c; j++)
                 {
                     s[i, j] = ss[i][j];
                 }
             }
             bool ok = true;
             for (int i = 0; i < r; i++)
             {
                 for (int j = 0; j < c; j++)
                 {
                     if (s[i, j] == '#')
                     {
                         if (i == r - 1 || j == c - 1)
                         {
                             ok = false;
                             break;
                         }
                         if (s[i + 1, j] != '#' || s[i, j + 1] != '#' || s[i + 1, j + 1] != '#')
                         {
                             ok = false;
                             break;
                         }
                         s[i, j]         = '/';
                         s[i, j + 1]     = '\\';
                         s[i + 1, j]     = '\\';
                         s[i + 1, j + 1] = '/';
                     }
                     if (!ok)
                     {
                         break;
                     }
                 }
                 if (!ok)
                 {
                     break;
                 }
             }
             prob.OutputCase();
             if (!ok)
             {
                 prob.WriteLine("Impossible");
             }
             else
             {
                 for (int i = 0; i < r; i++)
                 {
                     string ans = "";
                     for (int k = 0; k < c; k++)
                     {
                         ans += s[i, k];
                     }
                     prob.WriteLine(ans);
                 }
             }
         }
     }
 }
Beispiel #7
0
    static void Main(string[] args)
    {
        using (var prob = new CodeJamProblem('a', ProblemType.Large, 1))
        {
            var t = prob.ReadLineInt32();
            for (int c = 0; c < t; c++)
            {
                var info1 = prob.ReadInt32Array();
                var n     = info1[0];
                var k     = info1[1];
                var board = prob.ReadLines(n).Select(s => s.Select(ch => ".RB".IndexOf(ch)).ToArray()).ToArray();

                for (int i = 0; i < board.Length; i++)
                {
                    for (int r = 0; r < board[i].Length - 1; r++)
                    {
                        for (int j = board[i].Length - 1; j >= 1; j--)
                        {
                            if (board[i][j] == 0)
                            {
                                board[i][j]     = board[i][j - 1];
                                board[i][j - 1] = 0;
                            }
                        }
                    }
                }

                var red  = false;
                var blue = false;
                for (int i = 0; i < board.Length; i++)
                {
                    for (int j = 0; j < board[i].Length; j++)
                    {
                        var p = board[i][j];
                        if (p == 0)
                        {
                            continue;
                        }

                        var hl  = true;
                        var vl  = true;
                        var dll = true;
                        var drl = true;

                        for (int x = 1; x < k; x++)
                        {
                            if (j <= board[i].Length - k)
                            {
                                if (board[i][j + x] != p)
                                {
                                    hl = false;
                                }
                            }
                            else
                            {
                                hl = false;
                            }

                            if (i >= k - 1 && j <= board[i].Length - k)
                            {
                                if (board[i - x][j + x] != p)
                                {
                                    dll = false;
                                }
                            }
                            else
                            {
                                dll = false;
                            }

                            if (i <= board.Length - k)
                            {
                                if (board[i + x][j] != p)
                                {
                                    vl = false;
                                }
                            }
                            else
                            {
                                vl = false;
                            }

                            if (i <= board.Length - k && j <= board[i].Length - k)
                            {
                                if (board[i + x][j + x] != p)
                                {
                                    drl = false;
                                }
                            }
                            else
                            {
                                drl = false;
                            }
                        }

                        var hasLine = hl || vl || dll || drl;
                        if (p == 1)
                        {
                            red |= hasLine;
                        }
                        else if (p == 2)
                        {
                            blue |= hasLine;
                        }
                    }
                }

                if (red && blue)
                {
                    prob.OutputCase("Both");
                }
                else if (red)
                {
                    prob.OutputCase("Red");
                }
                else if (blue)
                {
                    prob.OutputCase("Blue");
                }
                else
                {
                    prob.OutputCase("Neither");
                }
            }
        }
    }
Beispiel #8
0
        static void Main(string[] args)
        {
            using (var prob = new CodeJamProblem("D:\\CodeJam\\test.in"))
            {
                var TestCount = prob.ReadLineInt32();

                for (var i = 0; i < TestCount; i++)
                {
                    prob.ReadInts(out MaxE, out R, out N);
                    AValues = prob.ReadInt32Array();
                    UsedE   = new int[N];

                    bool[] Tested     = new bool[N];
                    int    MaxGain    = 0;
                    int    MaxGainInd = -1;

                    bool Again = true;

                    while (Again)
                    {
                        Again      = false;
                        MaxGain    = 0;
                        MaxGainInd = -1;

                        for (var k = 0; k < N; k++)
                        {
                            if ((Tested[k] == false) && (AValues[k] > MaxGain))
                            {
                                MaxGainInd = k;
                                MaxGain    = AValues[k];
                            }
                        }
                        if (MaxGainInd > -1)
                        {
                            Tested[MaxGainInd] = true;
                            UsedE[MaxGainInd]  = CalcEnergy(MaxGainInd);
                            if (UsedE[MaxGainInd] > 0)
                            {
                                Again = true;
                            }
                            UsedE[MaxGainInd] -= Correct();
                            if (UsedE[MaxGainInd] > 0)
                            {
                                Again = true;
                            }
                            else
                            {
                                UsedE[MaxGainInd] = 0;
                            }
                            if (Correct() < 0)
                            {
                                Again = false;
                            }
                        }
                    }


                    int Gain = 0;
                    for (var k = 0; k < N; k++)
                    {
                        Gain += UsedE[k] * AValues[k];
                    }
                    prob.OutputCase(Gain);
                }
            }
        }
Beispiel #9
0
    static void Main(string[] args)
    {
        using (var prob = new CodeJamProblem('b', ProblemType.Large, 0))
        {
            int t = prob.ReadLineInt32();
            for (int cases = 0; cases < t; cases++)
            {
                int[,] combine = new int[26, 26];
                for (int i = 0; i < 26; i++)
                {
                    for (int j = 0; j < 26; j++)
                    {
                        combine[i, j] = -1;
                    }
                }

                bool[,] oppo = new bool[26, 26];

                string[] cur      = prob.ReadParts();
                int      ncombine = int.Parse(cur[0]);
                int      ind      = 1;
                for (int i = 0; i < ncombine; i++)
                {
                    int x = cur[ind][0] - 'A';
                    int y = cur[ind][1] - 'A';
                    int z = cur[ind][2] - 'A';
                    combine[x, y] = combine[y, x] = z;
                    ind++;
                }
                int noppo = int.Parse(cur[ind++]);
                for (int i = 0; i < noppo; i++)
                {
                    int x = cur[ind][0] - 'A';
                    int y = cur[ind][1] - 'A';
                    oppo[x, y] = oppo[y, x] = true;
                    ind++;
                }
                int         len   = int.Parse(cur[ind++]);
                Stack <int> stack = new Stack <int>();
                foreach (char c in cur[ind])
                {
                    int x = c - 'A';
                    if (stack.Count == 0)
                    {
                        stack.Push(x);
                        continue;
                    }
                    if (combine[x, stack.Peek()] != -1)
                    {
                        int y = stack.Pop();
                        stack.Push(combine[x, y]);
                        continue;
                    }

                    bool found = false;
                    for (int i = 0; i < 26; i++)
                    {
                        if (oppo[x, i] && stack.Contains(i))
                        {
                            found = true;
                            stack.Clear();
                            break;
                        }
                    }
                    if (!found)
                    {
                        stack.Push(x);
                    }
                }
                string ans = "[";
                int[]  s   = stack.ToArray();
                for (int i = s.Length - 1; i >= 0; i--)
                {
                    ans += (char)(s[i] + 'A');
                    if (i > 0)
                    {
                        ans += ", ";
                    }
                }
                ans += "]";
                prob.OutputCase(ans);
            }
        }
    }
Beispiel #10
0
 static void Main(string[] args)
 {
     using (var prob = new CodeJamProblem('b', ProblemType.Large, 0))
     {
         int tcase = prob.ReadLineInt32();
         for (int cases = 0; cases < tcase; cases++)
         {
             long[] a   = prob.ReadInt64Array();
             long   l   = a[0];
             long   t   = a[1];
             long   n   = a[2];
             long   c   = a[3];
             long   sum = 0;
             for (int i = 0; i < c; i++)
             {
                 a[i] = a[i + 4] * 2;
                 sum += a[i];
             }
             long left = t;
             int  now  = 0;
             long ans  = 0;
             while (now < n && left >= a[now % c])
             {
                 left -= a[now % c];
                 ans  += a[now % c];
                 now++;
             }
             if (now == n)
             {
                 prob.OutputCase(ans.ToString());
                 continue;
             }
             long[] ap = new long[11000 * 2];
             ans += left;
             ap[a[now % c] - left]++;
             long numleft = n - now - 1;
             for (int i = 0; i < c; i++)
             {
                 if (i < (numleft % c))
                 {
                     ap[a[(now + 1 + i) % c]] += numleft / c + 1;
                 }
                 else
                 {
                     ap[a[(now + 1 + i) % c]] += numleft / c;
                 }
             }
             for (int i = 21000; i >= 0; i--)
             {
                 if (ap[i] <= l)
                 {
                     l   -= ap[i];
                     ans += ap[i] * i / 2;
                 }
                 else
                 {
                     ans += ap[i] * i - (l * i / 2);
                     l    = 0;
                 }
             }
             prob.OutputCase(ans.ToString());
         }
     }
 }