結果
| 問題 |
No.8011 品物の並び替え (Extra)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-03-11 07:15:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,329 bytes |
| コンパイル時間 | 1,379 ms |
| コンパイル使用メモリ | 104,732 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-16 00:02:12 |
| 合計ジャッジ時間 | 17,736 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 WA * 2 |
コンパイルメッセージ
main.cpp:30:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
30 | main()
| ^~~~
ソースコード
#include<iostream>
#include<queue>
#include<algorithm>
#include<random>
using namespace std;
int N,M;
int S[50][50];
const int attempt=8000;
const int MaxTurn=70;
//const int SearchWidth=2;
struct state{
pair<int,vector<int> >A,B;
state()
{
A.first=B.first=0;
}
void push(const pair<int,vector<int> >&p)
{
if(A<p)
{
B=A;
A=p;
}
else if(B<p)
{
B=p;
}
}
};
main()
{
cin>>N>>M;
for(int i=0;i<M;i++)
{
int u,v,c;cin>>u>>v>>c;
S[u][v]=c;
}
mt19937 rng(0);
pair<int,vector<int> >ans{};
for(int atc=0;atc<attempt;atc++)
{
vector<int>fstate(N);
for(int i=0;i<N;i++)fstate[i]=i;
shuffle(fstate.begin(),fstate.end(),rng);
int cstate=0;
for(int i=0;i<N;i++)for(int j=i+1;j<N;j++)cstate+=S[fstate[i]][fstate[j]];
state P;
P.push(make_pair(cstate,fstate));
P.push(make_pair(cstate,fstate));
for(int turn=0;turn<MaxTurn;turn++)
{
vector<pair<int,vector<int> > >tmp={P.A,P.B};
for(pair<int,vector<int> >p:tmp)
{
int ns=p.first;
vector<int>id=p.second;
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]);
P.push(make_pair(ts,id));
swap(id[i],id[i+1]);
}
}
}
ans=max(ans,P.A);
}
cout<<ans.first<<endl;
for(int i=0;i<N;i++)cout<<ans.second[i]<<(i+1==N?"\n":" ");
}