結果

問題 No.3011 品物の並び替え (Extra)
ユーザー cielciel
提出日時 2015-05-04 00:36:23
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 917 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 58,348 KB
最終ジャッジ日時 2024-04-27 02:07:34
合計ジャッジ時間 544 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:22:9: error: ‘mt19937_64’ was not declared in this scope
   22 |         mt19937_64 engine((unsigned int)time(NULL)^(getpid()<<16));
      |         ^~~~~~~~~~
main.cpp:30:32: error: ‘engine’ was not declared in this scope
   30 |                 a=distribution(engine),b=distribution(engine);
      |                                ^~~~~~
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 #

//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