結果
| 問題 | 
                            No.8011 品物の並び替え (Extra)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2015-05-04 00:28:11 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                CE
                                 
                             
                            
                            (最新)
                                AC
                                 
                             
                            (最初)
                            
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 895 bytes | 
| コンパイル時間 | 444 ms | 
| コンパイル使用メモリ | 56,936 KB | 
| 最終ジャッジ日時 | 2024-11-14 19:03:07 | 
| 合計ジャッジ時間 | 806 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
            
            
            
            
            ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:20:9: error: ‘mt19937_64’ was not declared in this scope
   20 |         mt19937_64 engine((unsigned int)time(NULL)^(getpid()<<16));
      |         ^~~~~~~~~~
main.cpp:28:32: error: ‘engine’ was not declared in this scope
   28 |                 a=distribution(engine),b=distribution(engine);
      |                                ^~~~~~
main.cpp:12:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         scanf("%d%d",&N,&M);
      |         ~~~~~^~~~~~~~~~~~~~
main.cpp:16:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |                 scanf("%d%d%d",&a,&b,&c);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~
            
            ソースコード
#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]);
}