結果

問題 No.43 野球の試合
ユーザー sekiya9311
提出日時 2017-10-09 01:40:48
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 5,107 bytes
コンパイル時間 1,127 ms
コンパイル使用メモリ 119,164 KB
実行使用メモリ 27,800 KB
最終ジャッジ日時 2024-11-17 05:52:03
合計ジャッジ時間 2,108 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 5 WA * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #
プレゼンテーションモードにする

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProgrammingContest
{
class MainClass
{
Scanner sc;
static void Main(string[] args)
{
new MainClass().Solve();
}
void Solve()
{
#if DEBUG
string backPath = "..";
char dirSep = System.IO.Path.DirectorySeparatorChar;
string inFilePath = backPath + dirSep + backPath + dirSep + "in.txt";
sc = new Scanner(new System.IO.StreamReader(inFilePath));
#else
sc = new Scanner();
#endif
int n = sc.NextInt;
char[][] s = new char[n][].Select(chars => sc.Next.ToCharArray()).ToArray();
for (int i = 1; i < n; i++)
{
if (s[0][i] == '-')
{
s[0][i] = 'o';
s[i][0] = 'x';
}
}
List<Tuple<int, int>> list = new List<Tuple<int, int>>();
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (s[i][j] == '-')
{
list.Add(Tuple.Create(i, j));
}
}
}
if (list.Count == 0)
{
Write(Calc(n, s));
return;
}
int ans = 111;
for (int firstWin = 0; firstWin < (1 << list.Count); firstWin++)
{
for (int i = 0; i < list.Count; i++)
{
if ((firstWin & (1 << i)) != 0)
{
s[list[i].Item1][list[i].Item2] = 'o';
s[list[i].Item2][list[i].Item1] = 'x';
}
else
{
s[list[i].Item1][list[i].Item2] = 'x';
s[list[i].Item2][list[i].Item1] = 'o';
}
}
ans = Math.Min(ans, Calc(n, s));
}
Write(ans);
}
int Calc(int n, char[][] s)
{
int[] winCnt = new int[n];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (s[i][j] == 'o')
{
winCnt[i]++;
}
}
}
State[] st = new State[n];
for (int i = 0; i < n; i++)
{
st[i] = new State();
st[i].win = winCnt[i];
st[i].idx = i;
}
Array.Sort(st);
Array.Reverse(st);
for (int i = 0; i < n; i++)
{
if (st[i].idx == 0)
{
return i + 1;
}
}
throw new Exception();
}
struct State : IComparable<State>
{
public int win, idx;
public int CompareTo(State other)
{
int ret = Math.Sign(this.win - other.win);
if (ret == 0)
{
ret = Math.Sign(other.idx - this.idx);
}
return ret;
}
}
void Write(object val)
{
Console.WriteLine(val.ToString());
}
void Write(string format, params object[] vals)
{
Console.WriteLine(format, vals);
}
}
class Scanner
{
Queue<String> buffer;
char[] sep;
System.IO.TextReader reader;
public Scanner(System.IO.TextReader reader = null)
{
this.buffer = new Queue<string>();
this.sep = new char[] { ' ' };
this.reader = (reader ?? Console.In);
}
private void CheckBuffer()
{
if (this.buffer.Count == 0 && this.reader.Peek() >= 0)
{
string[] sreArray = this.reader.ReadLine().Split(this.sep);
foreach (String elStr in sreArray)
{
this.buffer.Enqueue(elStr);
}
}
}
public String Next
{
get
{
this.CheckBuffer();
return this.buffer.Dequeue();
}
}
public int NextInt
{
get
{
return int.Parse(this.Next);
}
}
public double NextDouble
{
get
{
return double.Parse(this.Next);
}
}
public long NextLong
{
get
{
return long.Parse(this.Next);
}
}
public bool IsEmpty
{
get
{
this.CheckBuffer();
return this.buffer.Count == 0;
}
}
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0