結果

問題 No.957 植林
ユーザー uwiuwi
提出日時 2019-12-20 20:31:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,612 bytes
コンパイル時間 2,250 ms
コンパイル使用メモリ 213,088 KB
実行使用メモリ 67,528 KB
最終ジャッジ日時 2023-09-23 04:10:04
合計ジャッジ時間 15,638 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
16,792 KB
testcase_01 AC 5 ms
11,996 KB
testcase_02 AC 6 ms
12,064 KB
testcase_03 AC 202 ms
27,768 KB
testcase_04 AC 162 ms
25,136 KB
testcase_05 AC 248 ms
28,148 KB
testcase_06 AC 137 ms
26,640 KB
testcase_07 AC 224 ms
26,412 KB
testcase_08 AC 119 ms
25,216 KB
testcase_09 AC 115 ms
25,672 KB
testcase_10 AC 161 ms
27,300 KB
testcase_11 AC 120 ms
25,384 KB
testcase_12 AC 123 ms
25,208 KB
testcase_13 AC 94 ms
23,268 KB
testcase_14 AC 120 ms
26,476 KB
testcase_15 AC 105 ms
25,348 KB
testcase_16 AC 97 ms
23,008 KB
testcase_17 AC 101 ms
25,120 KB
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In instantiation of ‘void HLPP<MAXN, T>::addEdge(int, int, int, bool) [with int MAXN = 100000; T = long long int]’:
main.cpp:118:13:   required from here
main.cpp:16:46: 警告: narrowing conversion of ‘((HLPP<100000, long long int>*)this)->HLPP<100000, long long int>::adj[to].std::vector<HLPP<100000, long long int>::edge, std::allocator<HLPP<100000, long long int>::edge> >::size()’ from ‘std::vector<HLPP<100000, long long int>::edge, std::allocator<HLPP<100000, long long int>::edge> >::size_type’ {aka ‘long unsigned int’} to ‘int’ [-Wnarrowing]
   16 |         adj[from].push_back({to, adj[to].size(), f});
      |                                  ~~~~~~~~~~~~^~
main.cpp:17:51: 警告: narrowing conversion of ‘(((HLPP<100000, long long int>*)this)->HLPP<100000, long long int>::adj[from].std::vector<HLPP<100000, long long int>::edge, std::allocator<HLPP<100000, long long int>::edge> >::size() - 1)’ from ‘std::vector<HLPP<100000, long long int>::edge, std::allocator<HLPP<100000, long long int>::edge> >::size_type’ {aka ‘long unsigned int’} to ‘int’ [-Wnarrowing]
   17 |         adj[to].push_back({from, adj[from].size() - 1, isDirected ? 0 : f});
      |                                  ~~~~~~~~~~~~~~~~~^~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template <int MAXN, class T = int> struct HLPP {
    const T INF = numeric_limits<T>::max();
    struct edge {
        int to, rev;
        T f;
    };
    int s = MAXN - 1, t = MAXN - 2;
    vector<edge> adj[MAXN];
    vector<int> lst[MAXN], gap[MAXN];
    T excess[MAXN];
    int highest, height[MAXN], cnt[MAXN], work;
    void addEdge(int from, int to, int f, bool isDirected = true) {
        adj[from].push_back({to, adj[to].size(), f});
        adj[to].push_back({from, adj[from].size() - 1, isDirected ? 0 : f});
    }
    void updHeight(int v, int nh) {
        work++;
        if (height[v] != MAXN)
            cnt[height[v]]--;
        height[v] = nh;
        if (nh == MAXN)
            return;
        cnt[nh]++, highest = nh;
        gap[nh].push_back(v);
        if (excess[v] > 0)
            lst[nh].push_back(v);
    }
    void globalRelabel() {
        work = 0;
        fill_n(height, MAXN, MAXN);
        fill_n(cnt, MAXN, 0);
        for (int i = 0; i < highest; i++)
            lst[i].clear(), gap[i].clear();
        height[t] = 0;
        queue<int> q({t});
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            for (auto &e : adj[v])
                if (height[e.to] == MAXN && adj[e.to][e.rev].f > 0)
                    q.push(e.to), updHeight(e.to, height[v] + 1);
            highest = height[v];
        }
    }
    void push(int v, edge &e) {
        if (excess[e.to] == 0)
            lst[height[e.to]].push_back(e.to);
        T df = min(excess[v], e.f);
        e.f -= df, adj[e.to][e.rev].f += df;
        excess[v] -= df, excess[e.to] += df;
    }
    void discharge(int v) {
        int nh = MAXN;
        for (auto &e : adj[v]) {
            if (e.f > 0) {
                if (height[v] == height[e.to] + 1) {
                    push(v, e);
                    if (excess[v] <= 0)
                        return;
                } else
                    nh = min(nh, height[e.to] + 1);
            }
        }
        if (cnt[height[v]] > 1)
            updHeight(v, nh);
        else {
            for (int i = height[v]; i <= highest; i++) {
                for (auto j : gap[i])
                    updHeight(j, MAXN);
                gap[i].clear();
            }
        }
    }
    T calc(int heur_n = MAXN) {
    	fill_n(excess, MAXN, 0);
        excess[s] = INF, excess[t] = -INF;
        globalRelabel();
        for (auto &e : adj[s])
            push(s, e);
        for (; highest >= 0; highest--) {
            while (!lst[highest].empty()) {
                int v = lst[highest].back();
                lst[highest].pop_back();
                discharge(v);
                if (work > 4 * heur_n)
                    globalRelabel();
            }
        }
        return excess[t] + INF;
    }
};

int n, m;
int G[305][305];
int R[305];
int C[305];
HLPP<100000, long long> D;

int main()
{
	scanf("%d %d", &n, &m);
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++){
			scanf("%d", &G[i][j]);
		}
	}
	for(int i = 0;i < n;i++){
		scanf("%d", &R[i]);
	}
	for(int i = 0;i < m;i++){
		scanf("%d", &C[i]);
	}
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++){
			D.addEdge(i*m+j, D.t, G[i][j]);
		}
	}
	long long ans = 0;
	for(int i = 0;i < n;i++){
		D.addEdge(D.s, n*m+i, R[i]);
		ans += R[i];
		for(int j = 0;j < m;j++){
			D.addEdge(n*m+i, i*m+j, R[i]);
		}
	}
	for(int i = 0;i < m;i++){
		D.addEdge(D.s, n*m+n+i, C[i]);
		ans += C[i];
		for(int j = 0;j < n;j++){
			D.addEdge(n*m+n+i, j*m+i, C[i]);
		}
	}

	ans -= D.calc();
	cout << ans << endl;

	return 0;
}
0