結果
| 問題 |
No.8011 品物の並び替え (Extra)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-03-11 07:21:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 971 bytes |
| コンパイル時間 | 960 ms |
| コンパイル使用メモリ | 98,916 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-16 00:02:59 |
| 合計ジャッジ時間 | 28,737 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 8 WA * 1 |
コンパイルメッセージ
main.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
10 | main()
| ^~~~
ソースコード
#include<iostream>
#include<queue>
#include<algorithm>
#include<random>
using namespace std;
int N,M;
int S[50][50];
const int attempt=1000;
const int MaxTurn=100000;
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]];
pair<int,vector<int> >p=make_pair(cstate,fstate);
for(int turn=0;turn<MaxTurn;turn++)
{
int ts=p.first;
int id=rng()%(N-1);
ts-=S[p.second[id]][p.second[id+1]];
ts+=S[p.second[id+1]][p.second[id]];
if(p.first<ts||p.first==ts&&rng()%2==1)
{
p.first=ts;
swap(p.second[id],p.second[id+1]);
}
}
ans=max(ans,p);
}
cout<<ans.first<<endl;
for(int i=0;i<N;i++)cout<<ans.second[i]<<(i+1==N?"\n":" ");
}