結果
問題 | No.3011 品物の並び替え (Extra) |
ユーザー | kotatsugame |
提出日時 | 2020-03-11 07:29:32 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 131 ms / 5,000 ms |
コード長 | 1,237 bytes |
コンパイル時間 | 1,142 ms |
コンパイル使用メモリ | 98,656 KB |
実行使用メモリ | 4,380 KB |
最終ジャッジ日時 | 2023-08-10 01:16:40 |
合計ジャッジ時間 | 3,396 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 126 ms
4,376 KB |
testcase_01 | AC | 122 ms
4,376 KB |
testcase_02 | AC | 131 ms
4,380 KB |
testcase_03 | AC | 123 ms
4,380 KB |
testcase_04 | AC | 121 ms
4,380 KB |
testcase_05 | AC | 122 ms
4,380 KB |
testcase_06 | AC | 122 ms
4,376 KB |
testcase_07 | AC | 121 ms
4,380 KB |
testcase_08 | AC | 126 ms
4,376 KB |
コンパイルメッセージ
main.cpp:11:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type] 11 | main() | ^~~~
ソースコード
#include<iostream> #include<queue> #include<algorithm> #include<random> using namespace std; int N,M; int S[50][50]; const int attempt=200; const int MaxTurn=10000; const int swapwd=5; 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); int wd=rng()%min(N-id-1,swapwd-1)+1; ts-=S[p.second[id]][p.second[id+wd]]; ts+=S[p.second[id+wd]][p.second[id]]; for(int i=1;i<wd;i++) { ts-=S[p.second[id]][p.second[id+i]]; ts-=S[p.second[id+i]][p.second[id+wd]]; ts+=S[p.second[id+wd]][p.second[id+i]]; ts+=S[p.second[id+i]][p.second[id]]; } if(p.first<ts||p.first==ts&&rng()%2==1) { p.first=ts; swap(p.second[id],p.second[id+wd]); } } ans=max(ans,p); } cout<<ans.first<<endl; for(int i=0;i<N;i++)cout<<ans.second[i]<<(i+1==N?"\n":" "); }