結果
| 問題 |
No.43 野球の試合
|
| コンテスト | |
| ユーザー |
mban
|
| 提出日時 | 2017-01-04 15:14:27 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,680 bytes |
| コンパイル時間 | 1,820 ms |
| コンパイル使用メモリ | 109,312 KB |
| 実行使用メモリ | 19,456 KB |
| 最終ジャッジ日時 | 2024-12-16 11:12:58 |
| 合計ジャッジ時間 | 2,272 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 6 WA * 1 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
class Magatro
{
static int N = int.Parse(Console.ReadLine());
static char[][] s;
static void Main()
{
s = new char[N][];
for(int i = 0; i < N; i++)
{
s[i] = Console.ReadLine().ToArray();
}
for(int i = 0; i < N; i++)
{
if (s[0][i] == '-')
{
s[0][i] = 'o';
s[i][0] = 'x';
}
}
List<XY> L = new List<XY>();
for(int i = 1; i < N - 1; i++)
{
for(int j = i + 1; j < N; j++)
{
if (s[i][j] == '-')
{
L.Add(new XY(j, i));
}
}
}
int loop = (int)Math.Pow(2, L.Count);
int min = int.MaxValue;
for(int i = 0; i < loop; i++)
{
int q = i;
char[][] copy = s.ToArray();
for(int j = 0; j < L.Count; j++)
{
if (q % 2 == 1)
{
copy[L[j].Y][L[j].X] = 'o';
copy[L[j].X][L[j].Y] = 'x';
}
else
{
copy[L[j].Y][L[j].X] = 'x';
copy[L[j].X][L[j].Y] = 'o';
}
q /= 2;
}
min = Math.Min(min, J(copy));
}
Console.WriteLine(min);
}
static int J(char[][] ss)
{
T[] Temp = new T[N];
for(int i = 0; i < N; i++)
{
Temp[i] = new T(i);
}
for(int i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
{
if (i == j)
{
continue;
}
if(ss[j][i]== 'o')
{
Temp[i].c++;
}
}
}
T[] copy = Temp.ToArray();
Array.Sort(copy, (a, b) => a.c.CompareTo(b.c));
int ans = 0;
int m = int.MaxValue;
for(int i = 0; i < N; i++)
{
if (m != copy[i].c)
{
ans++;
m = copy[i].c;
}
if (copy[i].index == 0)
{
return ans;
}
}
return -1;
}
}
struct XY
{
public int X, Y;
public XY(int x,int y)
{
X = x;
Y = y;
}
}
struct T
{
public int index, c;
public T(int i)
{
c = 0;
index = i;
}
}
mban