結果

問題 No.519 アイドルユニット
ユーザー goodbatongoodbaton
提出日時 2017-05-28 23:13:16
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,709 bytes
コンパイル時間 705 ms
コンパイル使用メモリ 84,564 KB
実行使用メモリ 237,036 KB
最終ジャッジ日時 2023-10-21 14:41:17
合計ジャッジ時間 11,729 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 1 ms
4,348 KB
testcase_05 WA -
testcase_06 AC 1 ms
4,348 KB
testcase_07 WA -
testcase_08 AC 1 ms
4,348 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 TLE -
testcase_33 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:63:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   63 |   scanf("%d",&n);
      |   ~~~~~^~~~~~~~~
main.cpp:67:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   67 |       scanf("%d",f[i]+j);
      |       ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 30

int dp[1<<24];
int visited[1<<24];
int last[1<<24];
int n;
int f[SIZE][SIZE];

vector<int> vec;
vector<int> vec2[24];

void dfs(int h, int key, int last_){

  last[key] = max(last[key],last_);
  
  if(visited[key]) return;
  visited[key] = true;
  vec2[h].push_back(key);

  if(h >= n-n/4*2){
    vec.push_back(key);
    return;
  }
  
  for(int j=last_;j<n;j++){
    if((1<<j) & key) continue;
    for(int k=j+1;k<n;k++){
      if((1<<k) & key) continue;

      dfs(h+2, key + (1<<j) + (1<<k), j+1);
    }
  }
}

int main(){
  
  scanf("%d",&n);

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      scanf("%d",f[i]+j);
    }
  }

  dfs(0,0,0);

  for(int i=0;i<n/4*2;i++){
    for(int t=0;t<vec2[i].size();t++){
      int key = vec2[i][t];
      
      for(int j=last[key];j<n;j++){
        if((1<<j) & key) continue;
        for(int k=j+1;k<n;k++){
          if((1<<k) & key) continue;
          
          int q = key + (1<<j) + (1<<k);
          
          dp[q] = max(dp[q], dp[key] + f[j][k]);
          
        }
      }
    }
  }
  
  int ans = 0;
  
  for(int i=0;i<vec.size();i++){
    int t = vec[i];
    
    ans = max(ans, dp[t] + dp[((1<<n)-1)^(t)]);

  }
   
  printf("%d\n",ans);
  
  return 0;
}
0