結果

問題 No.8011 品物の並び替え (Extra)
コンテスト
ユーザー ciel
提出日時 2015-05-04 00:36:23
言語 C++11(old_compat)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -include bits/stdc++.h -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1,452 ms / 5,000 ms
コード長 917 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,613 ms
コンパイル使用メモリ 182,112 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-03-08 16:02:16
合計ジャッジ時間 9,857 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 9
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:14:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |         scanf("%d%d",&N,&M);
      |         ~~~~~^~~~~~~~~~~~~~
main.cpp:18:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |                 scanf("%d%d%d",&a,&b,&c);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

//resubmission test.

#include <vector>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <ctime>
#include <unistd.h>
using namespace std;

int main(){
	int N,M;
	scanf("%d%d",&N,&M);
	unordered_map<int,unordered_map<int,int> >m;
	for(;M--;){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		m[a][b]=c;
	}
	uniform_int_distribution<int> distribution(0,N-1);
	mt19937_64 engine((unsigned int)time(NULL)^(getpid()<<16));
	vector<int>v(N),order(N);
	iota(order.begin(),order.end(),0);
	int r=0;
	for(int i=0;i<100000;i++){
		v=order;
		//random_shuffle(v.begin(),v.end());
		int a,b;
		a=distribution(engine),b=distribution(engine);
		swap(v[a],v[b]);
		a=distribution(engine),b=distribution(engine);
		swap(v[a],v[b]);
		int s=0;
		for(int i=0;i<N-1;i++)for(int j=i+1;j<N;j++)s+=m[v[i]][v[j]];
		if(r<s)r=s,order=v;
	};
	printf("%d",r);
	for(int i=0;i<N;i++)printf(" %d",order[i]);
}
0