結果

問題 No.3011 品物の並び替え (Extra)
ユーザー kotatsugamekotatsugame
提出日時 2020-03-11 06:49:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,013 bytes
コンパイル時間 1,098 ms
コンパイル使用メモリ 85,336 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-27 19:04:53
合計ジャッジ時間 6,255 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 370 ms
6,940 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
int N,M;
int S[50][50];
const int MaxTurn=1000;
const int SearchWidth=100;
main()
{
	cin>>N>>M;
	int initscore=0;
	for(int i=0;i<M;i++)
	{
		int u,v,c;cin>>u>>v>>c;
		S[u][v]=c;
		if(u<v)initscore+=c;
	}
	priority_queue<pair<int,vector<int> > >P;
	vector<int>initsort(N);
	for(int i=0;i<N;i++)initsort[i]=i;
	P.push(make_pair(initscore,initsort));
	for(int turn=0;turn<MaxTurn;turn++)
	{
		priority_queue<pair<int,vector<int> > >Q;
		while(!P.empty())
		{
			int ns=P.top().first;
			vector<int>id=P.top().second;
			P.pop();
			for(int i=0;i+1<N;i++)
			{
				int ts=ns;
				ts-=S[id[i]][id[i+1]];
				ts+=S[id[i+1]][id[i]];
				swap(id[i],id[i+1]);
				Q.push(make_pair(ts,id));
				swap(id[i],id[i+1]);
			}
		}
		for(int i=0;i<SearchWidth;i++)
		{
			if(Q.empty())break;
			P.push(Q.top());
			Q.pop();
		}
	}
	pair<int,vector<int> >ans=P.top();
	cout<<ans.first<<endl;
	for(int i=0;i<N;i++)cout<<ans.second[i]<<(i+1==N?"\n":" ");
}
0