結果

問題 No.1045 直方体大学
ユーザー yuji9511yuji9511
提出日時 2020-05-01 23:28:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,263 bytes
コンパイル時間 1,907 ms
コンパイル使用メモリ 176,604 KB
実行使用メモリ 138,732 KB
最終ジャッジ日時 2023-08-26 16:04:07
合計ジャッジ時間 6,820 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
138,364 KB
testcase_01 AC 72 ms
134,176 KB
testcase_02 AC 73 ms
133,952 KB
testcase_03 AC 72 ms
134,264 KB
testcase_04 AC 71 ms
134,172 KB
testcase_05 AC 166 ms
134,116 KB
testcase_06 AC 168 ms
134,156 KB
testcase_07 AC 165 ms
134,176 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
// using int = long long;
using lpair = pair<int, int>;
const int MOD = 1e9+7;
const int INF = 1e9;
#define rep(i,m,n) for(int i=(m);i<(n);i++)
#define rrep(i,m,n) for(int i=(m);i>=(n);i--)
#define printa(x,n) for(int i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
typedef struct {
    int h;
    int w;
    int c;
} P;
struct SegmentTreeMax {
private:
    int n;
    vector<int> node;

public:
    SegmentTreeMax(int N){
        int sz = N;
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, -INF);

        rep(i,0,sz) node[i+n-1] = 0;
        rrep(i,n-2,0) node[i] = max(node[2*i+1], node[2*i+2]);
    }

    void update(int x, int val){
        x += (n-1);
        node[x] = val;
        while(x > 0){
            x = (x-1)/2;
            node[x] = max(node[2*x+1], node[2*x+2]);
        }
    }

	void add(int x, int val){
		x += n-1;
		node[x] += val;
        while(x > 0){
            x = (x-1)/2;
            node[x] = max(node[2*x+1], node[2*x+2]);
        }
	}

    int getMax(int a, int b){
        int res = -INF;
        a += n; b += n;
        while(a < b){
            if(b & 1){
                b -= 1;
                res = max(res, node[b-1]);
            }
            if(a & 1){
                res = max(res, node[a-1]);
                a++;
            }
            a >>= 1; b >>= 1;
        }
        return res;
    }
    int getval(int x){
        return node[x + n-1];
    }
};
SegmentTreeMax sg(10000010);


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int A[20], B[20], C[20];
    rep(i,0,N) cin >> A[i] >> B[i] >> C[i];
    int ans = 0;
    int vv = 1;
    rep(i,0,N) vv *= 3;
    rep(bit,0,vv){
        vector<int> v(N,0);
        int idx = 0;
        int b = bit;
        while(b > 0){
            v[idx] = b % 3;
            b /= 3;
            idx++;
        }
        vector<P> lp;
        rep(i,0,N){
            if(v[i] == 0){
                int v1 = B[i], v2 = C[i];
                if(v1 > v2) swap(v1,v2);
                lp.push_back({v1,v2, A[i]});
            }else if(v[i] == 1){
                int v1 = B[i], v2 = A[i];
                if(v1 > v2) swap(v1,v2);
                lp.push_back({v1,v2, C[i]});          
            }else{
                int v1 = A[i], v2 = C[i];
                if(v1 > v2) swap(v1,v2);
                lp.push_back({v1,v2, B[i]});
            }
        }
        sort(lp.begin(), lp.end(), [](P l1, P l2){
            if(l1.h == l2.h){
                return l1.w < l2.w;
            }
            return l1.h < l2.h;
        });
        // rep(i,0,N){
        //     print(lp[i].h, lp[i].w, lp[i].c);
        // }
        // print("===");
        int dp[20] = {};
        rep(i,0,N){
            dp[i] = sg.getMax(1, lp[i].w+1) + lp[i].c;
            // if(bit == 7) print(i);
            int v = sg.getval(lp[i].w);
            v = max(v, dp[i]);
            sg.update(lp[i].w, v);
        }
        rep(i,0,N){
            sg.update(lp[i].w, 0);
        }
        ans = max(ans, dp[N-1]);



    }
    print(ans);
    

}
0