結果

問題 No.3011 品物の並び替え (Extra)
ユーザー tailstails
提出日時 2015-05-04 00:08:12
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 815 bytes
コンパイル時間 1,669 ms
コンパイル使用メモリ 144,488 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-19 05:46:40
合計ジャッジ時間 16,944 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4,211 ms
7,516 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int  n,m;
int t[50][50];
int a[50],b[50];

int main(){
  cin>>n>>m;
  for(int j=0;j<m;++j){
    int a,b,s;
    cin >>a>>b>>s;
    t[a][b]=s;
  }
  
  srand(1);
  for(int i=0;i<n;++i){
    a[i]=i;
  }
  int e=0;

  for(int c=0;c<10000000;++c){
    for(int i=0;i<n;++i){
      b[i]=a[i];
    }
    {
      int i=rand()%n;
      int j=rand()%n;
      if(i!=j)b[i]^=b[j]^=b[i]^=b[j];
    }
    {
      int i=rand()%n;
      int j=rand()%n;
      if(i!=j)b[i]^=b[j]^=b[i]^=b[j];
    }
    int r=0;
    for(int i=0;i<n;++i){
      for(int j=i+1;j<n;++j){
	r+=t[b[i]][b[j]];
      }
    }
    if(r>e){
      e=r;
      for(int i=0;i<n;++i){
	a[i]=b[i];
      }
    }
  }
  cout << e << endl;
  for(int i=0;i<n;++i){
    cout << a[i] << " ";
  }
  cout << endl;
  return 0;
}
0