結果

問題 No.519 アイドルユニット
ユーザー どららどらら
提出日時 2017-05-28 22:26:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,453 bytes
コンパイル時間 1,762 ms
コンパイル使用メモリ 171,000 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 14:21:28
合計ジャッジ時間 2,997 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 3 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 WA -
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 WA -
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 WA -
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;

#define INF 100000000
int cost[30][30];

void hungarian(vector<int> &x, vector<int> &y){
  int n = x.size();
  int p, q;
  vector<int> fx(n,INF), 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 = INF;
      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];
      if(i==j) cost[i][j] = 0;
    }
  }
  vector<int> x(N,-1), y(N,-1);
  hungarian(x, y);

  int ret = 0;
  rep(i,N){
    assert(x[i] != -1);
    assert(y[i] != -1);
    ret += cost[i][x[i]];
  }
  cout << ret/2 << endl;
  return 0;
}

0