結果
| 問題 |
No.8011 品物の並び替え (Extra)
|
| コンテスト | |
| ユーザー |
Lepton_s
|
| 提出日時 | 2015-05-04 00:20:35 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,088 bytes |
| コンパイル時間 | 900 ms |
| コンパイル使用メモリ | 93,644 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-05 18:28:44 |
| 合計ジャッジ時間 | 2,169 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 9 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:65:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
65 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:68:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
68 | scanf("%d %d %d", &a, &b, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<25;
typedef pair<int,int> P;
typedef long long ll;
typedef unsigned long long ull;
#define N 64
#define M 1000
#define L 100
int n, m;
int g[N][N], r[N], l[N];
int calc(vector<int> &a){
int s = 0;
for(int i = 0; i < n; i++){
for(int j = i+1; j < n; j++){
s += g[a[i]][a[j]];
}
}
return s;
}
int opt(vector<int> &a){
int res = calc(a);
for(int i = 0; i < L; i++){
int b = rand()%n, c = rand()%n;
swap(a[b], a[c]);
int r = calc(a);
if(r<res){
swap(a[b], a[c]);
continue;
}
res = r;
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n-1; j++){
if(g[a[j]][a[j+1]]<g[a[j+1]][a[j]]) swap(a[j], a[j+1]);
}
}
return res;
}
int main(){
srand(time(NULL));
scanf("%d%d", &n, &m);
for(int i = 0; i < m; i++){
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
g[a][b] = c;
r[b] += c;
l[a] += c;
}
vector<int> res[M];
vector<P> xx[2];
for(int i = 0; i < n; i++){
xx[0].push_back(P(r[i], i));
xx[1].push_back(P(l[i], i));
}
sort(xx[0].begin(), xx[0].end());
sort(xx[1].begin(), xx[1].end());
for(int i = 0; i < n; i++){
res[0].push_back(xx[0][i].second);
res[1].push_back(xx[1][n-i-1].second);
res[2].push_back(i);
}
for(int i = 3; i < M; i++) res[i] = res[2];
for(int i = 2; i < M; i++)
random_shuffle(res[i].begin(), res[i].end());
/*
for(int i = 0; i < M; i++){
for(int j = 0; j < n; j++){
cout<<res[i][j]<<" ";
}
cout<<endl;
}
*/
int sc[M];
for(int i = 0; i < M; i++) sc[i] = opt(res[i]);
int mxp = 0;
for(int i = 1; i < M; i++){
if(sc[mxp]<sc[i]) mxp = i;
}
printf("%d\n", sc[mxp]);
for(int i = 0; i < n; i++) printf("%d ", res[mxp][i]);
return 0;
}
Lepton_s