結果

問題 No.43 野球の試合
ユーザー cielciel
提出日時 2014-12-02 02:07:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 1,107 bytes
コンパイル時間 1,146 ms
コンパイル使用メモリ 73,348 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-02 00:59:48
合計ジャッジ時間 2,041 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 9 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;
int calc(const vector<int> &v){
	vector<pair<int,int> > srt(v.size());
	for(int i=0;i<v.size();i++)srt[i]=make_pair(-v[i],i);
	sort(srt.begin(),srt.end());
	int rank=1,cur=srt[0].first;
	for(int i=0;i<srt.size();i++){
		if(cur<srt[i].first)rank++,cur=srt[i].first;
		if(srt[i].second==0)return rank;
	}
	abort();
}
int main(){
	int n;
	string s;
	vector<pair<int,int> >match;
	cin>>n;
	vector<int>win(n);
	for(int i=0;i<n;i++){
		cin>>s;
		for(int j=i+1;j<n;j++){
			if(s[j]=='o')win[i]++;
			else if(s[j]=='x')win[j]++;
			else if(s[j]=='-')match.push_back(make_pair(i,j));
		}
	}
	int result=n;
	if(match.empty())result=calc(win);
	for(int i=0;i<1<<match.size();i++){
		for(int j=0;j<match.size();j++){
			if(i&(1<<j))win[match[j].first]++;
			else win[match[j].second]++;
		}
		result=min(result,calc(win));
		for(int j=0;j<match.size();j++){
			if(i&(1<<j))win[match[j].first]--;
			else win[match[j].second]--;
		}
	}
	cout<<result<<endl;
}
0