Submission #3299419
Source Code Expand
using static System.Console;
using System.Linq;
using System.Collections.Generic;
namespace ConsoleApp4
{
class Program
{
static void Main(string[] args)
{
var n = int.Parse(ReadLine());
var vs = ReadLine().Split(' ');
var odd = new List<string>();
var even = new List<string>();
for (var i = 0; i < n; i++)
{
if (i % 2 == 0)
{
even.Add(vs[i]);
}
else
{
odd.Add(vs[i]);
}
}
var e2 = even
.GroupBy(x => x);
var o2 = odd
.GroupBy(x => x);
if (e2.Count() == 1 && o2.Count() == 1)
{
if (e2.First().Key == o2.First().Key)
{
WriteLine(n / 2);
}
else
{
WriteLine(0);
}
}
else
{
if (e2.Count() == 1)
{
var o3 = o2
.Select(x => new { Value = x, Count = x.Count() })
.OrderByDescending(x => x.Count);
if (e2.First().Key != o3.First().Value.Key)
{
WriteLine(n / 2 - o3.First().Count);
}
else
{
WriteLine(n / 2 - o3.Skip(1).First().Count);
}
}
else if (o2.Count() == 1)
{
var e3 = e2
.Select(x => new { Value = x, Count = x.Count() })
.OrderByDescending(x => x.Count);
if (o2.First().Key != e3.First().Value.Key)
{
WriteLine(n / 2 - e3.First().Count);
}
else
{
WriteLine(n / 2 - e3.Skip(1).First().Count);
}
}
else
{
var o3 = o2
.Select(x => new { Value = x, Count = x.Count() })
.OrderByDescending(x => x.Count);
var e3 = e2
.Select(x => new { Value = x, Count = x.Count() })
.OrderByDescending(x => x.Count);
if (o3.First().Value.Key != e3.First().Value.Key)
{
WriteLine((n / 2 - o3.First().Count) + (n / 2 - e3.First().Count));
}
else
{
if (o3.First().Count == e3.First().Count)
{
WriteLine((n / 2 - System.Math.Max(o3.Skip(1).First().Count, e3.Skip(1).First().Count)) + (n / 2 - o3.First().Count));
}
else if (o3.First().Count < e3.First().Count)
{
WriteLine((n / 2 - e3.First().Count) + (n / 2 - o3.Skip(1).First().Count));
}
else
{
WriteLine((n / 2 - o3.First().Count) + (n / 2 - e3.Skip(1).First().Count));
}
}
}
}
}
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - /\/\/\/ |
| User | MayoToya |
| Language | C# (Mono 4.6.2.0) |
| Score | 300 |
| Code Size | 3629 Byte |
| Status | AC |
| Exec Time | 410 ms |
| Memory | 56720 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 300 / 300 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample1_3132.txt, sample2_iw.txt, sample3_1111.txt |
| All | ababa_0.txt, ababa_1.txt, eq_0.txt, eq_1.txt, rnd_17.txt, sample1_3132.txt, sample2_iw.txt, sample3_1111.txt, top2_0.txt, top2_1.txt, top2_2.txt, top2_3.txt, top2modoki_0.txt, top2modoki_1.txt, top2modoki_2.txt, top2modoki_3.txt, vary_1.txt, vary_2.txt, vary_3.txt, zoro_0.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| ababa_0.txt | AC | 183 ms | 42996 KiB |
| ababa_1.txt | AC | 156 ms | 40420 KiB |
| eq_0.txt | AC | 85 ms | 30816 KiB |
| eq_1.txt | AC | 85 ms | 28768 KiB |
| rnd_17.txt | AC | 94 ms | 35548 KiB |
| sample1_3132.txt | AC | 31 ms | 9564 KiB |
| sample2_iw.txt | AC | 27 ms | 9428 KiB |
| sample3_1111.txt | AC | 27 ms | 11476 KiB |
| top2_0.txt | AC | 142 ms | 31836 KiB |
| top2_1.txt | AC | 113 ms | 33460 KiB |
| top2_2.txt | AC | 137 ms | 31708 KiB |
| top2_3.txt | AC | 139 ms | 33464 KiB |
| top2modoki_0.txt | AC | 111 ms | 33756 KiB |
| top2modoki_1.txt | AC | 114 ms | 31408 KiB |
| top2modoki_2.txt | AC | 112 ms | 35932 KiB |
| top2modoki_3.txt | AC | 114 ms | 33464 KiB |
| vary_1.txt | AC | 282 ms | 51292 KiB |
| vary_2.txt | AC | 410 ms | 56720 KiB |
| vary_3.txt | AC | 241 ms | 45032 KiB |
| zoro_0.txt | AC | 27 ms | 9312 KiB |