結果

問題 No.3011 品物の並び替え (Extra)
ユーザー Kmcode1Kmcode1
提出日時 2015-05-04 02:05:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4,829 ms / 5,000 ms
コード長 1,678 bytes
コンパイル時間 959 ms
コンパイル使用メモリ 97,644 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-19 06:38:02
合計ジャッジ時間 50,432 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4,823 ms
4,380 KB
testcase_01 AC 4,824 ms
4,380 KB
testcase_02 AC 4,825 ms
4,380 KB
testcase_03 AC 4,823 ms
4,376 KB
testcase_04 AC 4,829 ms
4,380 KB
testcase_05 AC 4,824 ms
4,376 KB
testcase_06 AC 4,825 ms
4,376 KB
testcase_07 AC 4,823 ms
4,380 KB
testcase_08 AC 4,826 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
using namespace std;

int n;
int m;
#define MAX 51
vector<pair<int, pair<int, int> > > v;
vector<int> ans;
int maxt = 0;
vector<int> ord;
int flag[MAX];
void score(){
	for (int i = 0; i < ord.size(); i++){
		flag[ord[i]] = i;
	}
	int kari = 0;
	for (int i = 0; i < v.size(); i++){
		if (flag[v[i].first] < flag[v[i].second.first]){
			kari += v[i].second.second;
		}
	}
	if (maxt < kari){
		maxt = kari;
		ans = ord;
	}
}
int main(){
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		v.push_back(make_pair(a, make_pair(b, c)));
	}
	for (int i = 0; i < n; i++){
		ord.push_back(i);
	}
	maxt = -1;
	score();
	reverse(ord.begin(), ord.end());
	score();
	reverse(ord.begin(), ord.end());
	int a, b;
	bool ok = false;
	while (clock()  / (double)(CLOCKS_PER_SEC) < 4.8){
		a = rand() % ord.size();
		b = rand() % ord.size();
		swap(ord[a], ord[b]);
		long long int prev = maxt;
		score();
		if (prev == maxt){
			swap(ord[a], ord[b]);
		}
		if (!ok){
			if (clock() / (double)(CLOCKS_PER_SEC) > 2.5){
				reverse(ord.begin(), ord.end());
				ok = true;
			}
		}
	}
	printf("%d\n", maxt);
	for (int i = 0; i < ans.size(); i++){
		if (i){
			cout << " ";
		}
		cout << ans[i];
	}
	puts("");
	return 0;
}
0