結果
問題 | No.43 野球の試合 |
ユーザー |
|
提出日時 | 2014-12-02 02:07:29 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 8 ms / 5,000 ms |
コード長 | 1,107 bytes |
コンパイル時間 | 778 ms |
コンパイル使用メモリ | 70,260 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-11 07:35:42 |
合計ジャッジ時間 | 1,628 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 |
ソースコード
#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; }