結果

問題 No.43 野球の試合
ユーザー kotatsugamekotatsugame
提出日時 2017-10-09 23:09:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 773 bytes
コンパイル時間 534 ms
コンパイル使用メモリ 68,840 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-10 21:22:03
合計ジャッジ時間 1,253 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:43:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   43 | main()
      | ^~~~
main.cpp: 関数 ‘int dfs(int)’ 内:
main.cpp:42:1: 警告: 制御が非 void 関数の終りに到達しました [-Wreturn-type]
   42 | }
      | ^

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
string s[7];int n;
int dfs(int t)
{
	if(t)
	{
		int ret=1e9;
		for(int i=0;i<n;i++)
		{
			for(int j=i;j<n;j++)
			{
				if(s[i][j]=='-')
				{
					s[i][j]='o';s[j][i]='x';ret=min(ret,dfs(t-1));
					s[i][j]='x';s[j][i]='o';ret=min(ret,dfs(t-1));
					s[i][j]=s[j][i]='-';
					return ret;
				}
			}
		}
		return ret;
	}
	else
	{
		int c[7]={};
		for(int i=0;i<n;i++)for(int j=0;j<n;j++)c[i]+=s[i][j]=='o';
		int ret=0;
		for(int i=n;i--;)
		{
			for(int j=0;j<n;j++)
			{
				if(c[j]==i){ret++;break;}
			}
			if(c[0]==i)
			{
				return ret;
			}
		}
	}
}
main()
{
	cin>>n;for(int i=0;i<n;i++)cin>>s[i];
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i;j<n;j++)cnt+=s[i][j]=='-';
	}
	cout<<dfs(cnt)<<endl;
}
0