結果
| 問題 | 
                            No.519 アイドルユニット
                             | 
                    
| コンテスト | |
| ユーザー | 
                             どらら
                         | 
                    
| 提出日時 | 2017-05-28 22:17:10 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,361 bytes | 
| コンパイル時間 | 2,263 ms | 
| コンパイル使用メモリ | 169,920 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-09-21 15:33:01 | 
| 合計ジャッジ時間 | 2,771 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 27 WA * 7 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
int cost[30][30];
void hungarian(vector<int> &x, vector<int> &y){
  int n = x.size();
  int p, q;
  vector<int> fx(n,1000000), fy(n,0);
  for(int i=0; i<n; i++) for(int j=0; j<n; j++) fx[i] = max(fx[i],cost[i][j]);
  for(int i=0; i<n;){
    vector<int> t(n,-1), s(n+1,i);
    for(p=q=0; p<=q && x[i]<0; ++p)
      for(int k=s[p],j=0; j<n && x[i]<0; ++j)
        if(fx[k]+fy[j]==cost[k][j] && t[j]<0){
          s[++q] = y[j], t[j] = k;
          if(s[q]<0) for(p=j; p>=0; j=p) y[j] = k = t[j], p = x[k], x[k] = j;
        }
    if(x[i]<0){
      int d = 10000000;
      for(int k=0; k<=q; ++k) for(int j=0; j<n; ++j)
        if(t[j]<0) d = min(d, fx[s[k]] + fy[j] - cost[s[k]][j]);
      for(int j = 0; j < n; ++j) fy[j] += (t[j] < 0 ? 0 : d);
      for(int k = 0; k <= q; ++k) fx[s[k]] -= d;
    } else ++i;
  }
}
int main(){
  int N;
  cin >> N;
  rep(i,N){
    rep(j,N){
      cin >> cost[i][j];
    }
  }
  vector<int> x(N,-1), y(N,-1);
  hungarian(x, y);
  int ret = 0;
  rep(i,N){
    ret += cost[i][x[i]];
  }
  cout << ret/2 << endl;
  return 0;
}
            
            
            
        
            
どらら