結果
| 問題 |
No.43 野球の試合
|
| コンテスト | |
| ユーザー |
Dadarithm
|
| 提出日時 | 2015-10-11 03:41:28 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 23 ms / 5,000 ms |
| コード長 | 1,250 bytes |
| コンパイル時間 | 1,150 ms |
| コンパイル使用メモリ | 79,572 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-21 06:17:19 |
| 合計ジャッジ時間 | 1,821 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int N; vector<string> s; vector<pair<int, int>> pos;
int dfs(int depth)
{
if (depth == 0)
{
vector<string> tmp = s;
const string key = s[0];
sort(s.begin(), s.end(), [](string i, string j){ return count(i.begin(), i.end(), 'o') > count(j.begin(), j.end(), 'o'); });
for (int i = 0; i < N; ++i)
{
if (s[i] == key)
{
int counter = 0;
for (int j = 0; j < i; ++j)
{
if (count(s[j].begin(), s[j].end(), 'o') == count(s[j + 1].begin(), s[j + 1].end(), 'o'))
++counter;
}
s = tmp;
return i + 1 - counter;
}
}
}
s[pos[depth - 1].first][pos[depth - 1].second] = 'o';
s[pos[depth - 1].second][pos[depth - 1].first] = 'x';
int a = dfs(depth - 1);
s[pos[depth - 1].first][pos[depth - 1].second] = 'x';
s[pos[depth - 1].second][pos[depth - 1].first] = 'o';
int b = dfs(depth - 1);
return min(a, b);
}
int main()
{
cin >> N;
for (int i = 0; i < N; ++i)
{
string tmp;
cin >> tmp;
s.push_back(tmp);
}
for (int i = 0; i < N; ++i)
{
for (int j = 0; j < i; ++j)
{
if (s[i][j] == '-')
pos.push_back(pair<int, int>(i, j));
}
}
cout << dfs(pos.size()) << endl;
return 0;
}
Dadarithm