結果

問題 No.3011 品物の並び替え (Extra)
ユーザー なおなお
提出日時 2015-05-04 01:00:38
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,321 bytes
コンパイル時間 1,317 ms
コンパイル使用メモリ 151,044 KB
実行使用メモリ 11,988 KB
最終ジャッジ日時 2023-09-19 06:27:42
合計ジャッジ時間 14,005 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))
#define FOR(i, f, t)        for(int(i)=(f);(i)<(t);(++i))
const int MOD = int(1e9+9);

int N,M;
int k[55],kk[55];
map<int,int> m[55];

unsigned int xor128(void) {
    static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
    unsigned int t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}

int score(){
    ll mask = 0;
    int sc = 0;
    REP(i,N){
        auto &a = m[k[i]];
        for(auto it = a.begin(); it != a.end(); ++it){
            int b = it->first, c = it->second;
            if((mask >> b)&1) continue;
            sc += c;
        }
        mask |= 1LL<<k[i];
    }
    return sc;
}

int main(){
    cin >> N >> M;
    REP(i,M){
        int a,b,c;
        cin >> a >> b >> c;
        m[a].insert(make_pair(b,c));
    }

    REP(i,N) k[i] = kk[i] = i;
    int sc = score();

    clock_t t = clock() + CLOCKS_PER_SEC * 10;
    while(t >= clock()){
        int i = xor128() % N;
        int j = xor128() % N;
        if(i == j) continue;
        swap(k[i],k[j]);
        int s = score();
        if(sc < s){
            sc = s;
            REP(i,N) kk[i] = k[i];
        }
    }

    cout << sc << endl;
    REP(i,N) cout << kk[i] << " ";
    return 0;
}
0