結果

問題 No.1014 competitive fighting
ユーザー FF256grhyFF256grhy
提出日時 2020-09-09 18:27:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 370 ms / 2,000 ms
コード長 8,612 bytes
コンパイル時間 3,137 ms
コンパイル使用メモリ 229,348 KB
実行使用メモリ 34,400 KB
最終ジャッジ日時 2024-12-16 00:34:42
合計ジャッジ時間 17,771 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 359 ms
31,700 KB
testcase_06 AC 363 ms
31,828 KB
testcase_07 AC 370 ms
31,952 KB
testcase_08 AC 368 ms
31,828 KB
testcase_09 AC 367 ms
31,952 KB
testcase_10 AC 233 ms
16,956 KB
testcase_11 AC 294 ms
20,200 KB
testcase_12 AC 365 ms
31,952 KB
testcase_13 AC 167 ms
16,728 KB
testcase_14 AC 153 ms
15,636 KB
testcase_15 AC 184 ms
18,020 KB
testcase_16 AC 9 ms
5,248 KB
testcase_17 AC 64 ms
8,432 KB
testcase_18 AC 292 ms
26,568 KB
testcase_19 AC 361 ms
30,780 KB
testcase_20 AC 120 ms
13,024 KB
testcase_21 AC 260 ms
24,296 KB
testcase_22 AC 219 ms
20,552 KB
testcase_23 AC 83 ms
10,144 KB
testcase_24 AC 87 ms
10,376 KB
testcase_25 AC 22 ms
5,248 KB
testcase_26 AC 256 ms
23,944 KB
testcase_27 AC 62 ms
8,428 KB
testcase_28 AC 70 ms
9,132 KB
testcase_29 AC 5 ms
5,248 KB
testcase_30 AC 350 ms
30,944 KB
testcase_31 AC 272 ms
24,864 KB
testcase_32 AC 4 ms
5,248 KB
testcase_33 AC 23 ms
5,248 KB
testcase_34 AC 272 ms
27,652 KB
testcase_35 AC 353 ms
34,400 KB
testcase_36 AC 234 ms
22,904 KB
testcase_37 AC 9 ms
5,248 KB
testcase_38 AC 214 ms
22,432 KB
testcase_39 AC 109 ms
13,416 KB
testcase_40 AC 206 ms
20,948 KB
testcase_41 AC 142 ms
16,152 KB
testcase_42 AC 329 ms
30,324 KB
testcase_43 AC 18 ms
5,248 KB
testcase_44 AC 300 ms
29,588 KB
testcase_45 AC 177 ms
19,116 KB
testcase_46 AC 31 ms
5,940 KB
testcase_47 AC 99 ms
12,492 KB
testcase_48 AC 249 ms
25,984 KB
testcase_49 AC 11 ms
5,248 KB
testcase_50 AC 317 ms
29,604 KB
testcase_51 AC 180 ms
18,380 KB
testcase_52 AC 13 ms
5,248 KB
testcase_53 AC 361 ms
31,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); i++)
#define incIX(i, l, r) for(LL i = (l)    ; i <  (r); i++)
#define incXI(i, l, r) for(LL i = (l) + 1; i <= (r); i++)
#define incXX(i, l, r) for(LL i = (l) + 1; i <  (r); i++)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); i--)
#define decIX(i, l, r) for(LL i = (r) - 1; i >= (l); i--)
#define decXI(i, l, r) for(LL i = (r)    ; i >  (l); i--)
#define decXX(i, l, r) for(LL i = (r) - 1; i >  (l); i--)
#define inc(i, n)  incIX(i, 0, n)
#define dec(i, n)  decIX(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
auto inII = [](auto x, auto l, auto r) { return (l <= x && x <= r); };
auto inIX = [](auto x, auto l, auto r) { return (l <= x && x <  r); };
auto inXI = [](auto x, auto l, auto r) { return (l <  x && x <= r); };
auto inXX = [](auto x, auto l, auto r) { return (l <  x && x <  r); };
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define RV(c) reverse(ALL(c))
#define SC static_cast
#define SI(c) SC<int>(c.size())
#define SL(c) SC<LL >(c.size())
#define RF(e, c) for(auto & e: c)
#define SF(c, ...) for(auto & [__VA_ARGS__]: c)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
auto * IS = & cin;
auto * OS = & cout;
array<string, 3> SEQ = { "", " ", "" };
// input elements (as a tuple)
template<typename U, int I> void in_([[maybe_unused]] U & t) { }
template<typename U, int I, typename A, typename ... B> void in_(U & t) { (* IS) >> get<I>(t); in_<U, I + 1, B ...>(t); }
template<typename ... T> auto in() { tuple<T ...> t; in_<tuple<T ...>, 0, T ...>(t); return t; }
// input an array
template<typename T, int N> auto ain() { array<T, N> a; inc(i, N) { (* IS) >> a[i]; } return a; }
// input a (multi-dimensional) vector
template<typename T> T vin() { T v; (* IS) >> v; return v; }
template<typename T, typename N, typename ... M> auto vin(N n, M ... m) {
	vector<decltype(vin<T, M ...>(m ...))> v(n); inc(i, n) { v[i] = vin<T, M ...>(m ...); } return v;
}
// input multi-column (as a tuple of vector)
template<typename U, int I> void colin_([[maybe_unused]] U & t) { }
template<typename U, int I, typename A, typename ... B> void colin_(U & t) {
	A a; (* IS) >> a; get<I>(t).push_back(a); colin_<U, I + 1, B ...>(t);
}
template<typename ... T> auto colin(int n) {
	tuple<vector<T> ...> t; inc(i, n) { colin_<tuple<vector<T> ...>, 0, T ...>(t); } return t;
}
// output elements
void out_([[maybe_unused]] string s) { }
template<typename A> void out_([[maybe_unused]] string s, A && a) { (* OS) << a; }
template<typename A, typename ... B> void out_(string s, A && a, B && ... b) { (* OS) << a << s; out_(s, b ...); }
auto outF = [](auto x, auto y, auto z, auto ... a) { (* OS) << x; out_(y, a ...); (* OS) << z << flush; };
auto out  = [](auto ... a) { outF("", " " , "\n", a ...); };
auto outS = [](auto ... a) { outF("", " " , " " , a ...); };
auto outL = [](auto ... a) { outF("", "\n", "\n", a ...); };
auto outN = [](auto ... a) { outF("", ""  , ""  , a ...); };
// output a (multi-dimensional) vector
template<typename T> ostream & operator<<(ostream & os, vector<T> const & v) {
	os << SEQ[0]; inc(i, SI(v)) { os << (i == 0 ? "" : SEQ[1]) << v[i]; } return (os << SEQ[2]);
}
template<typename T> void vout_(T && v) { (* OS) << v; }
template<typename T, typename A, typename ... B> void vout_(T && v, A a, B ... b) {
	inc(i, SI(v)) { (* OS) << (i == 0 ? "" : a); vout_(v[i], b ...); }
}
template<typename T, typename A, typename ... B> void vout(T && v, A a, B ... b) {
	vout_(v, b ...); (* OS) << a << flush;
}

// ---- ----


#include <algorithm>

#include <algorithm>
#include <utility>
#include <vector>

namespace atcoder {
namespace internal {

template <class E> struct csr {
    std::vector<int> start;
    std::vector<E> elist;
    csr(int n, const std::vector<std::pair<int, E>>& edges)
        : start(n + 1), elist(edges.size()) {
        for (auto e : edges) {
            start[e.first + 1]++;
        }
        for (int i = 1; i <= n; i++) {
            start[i] += start[i - 1];
        }
        auto counter = start;
        for (auto e : edges) {
            elist[counter[e.first]++] = e.second;
        }
    }
};

// Reference:
// R. Tarjan,
// Depth-First Search and Linear Graph Algorithms
struct scc_graph {
  public:
    scc_graph(int n) : _n(n) {}

    int num_vertices() { return _n; }

    void add_edge(int from, int to) { edges.push_back({from, {to}}); }

    // @return pair of (# of scc, scc id)
    std::pair<int, std::vector<int>> scc_ids() {
        auto g = csr<edge>(_n, edges);
        int now_ord = 0, group_num = 0;
        std::vector<int> visited, low(_n), ord(_n, -1), ids(_n);
        visited.reserve(_n);
        auto dfs = [&](auto self, int v) -> void {
            low[v] = ord[v] = now_ord++;
            visited.push_back(v);
            for (int i = g.start[v]; i < g.start[v + 1]; i++) {
                auto to = g.elist[i].to;
                if (ord[to] == -1) {
                    self(self, to);
                    low[v] = std::min(low[v], low[to]);
                } else {
                    low[v] = std::min(low[v], ord[to]);
                }
            }
            if (low[v] == ord[v]) {
                while (true) {
                    int u = visited.back();
                    visited.pop_back();
                    ord[u] = _n;
                    ids[u] = group_num;
                    if (u == v) break;
                }
                group_num++;
            }
        };
        for (int i = 0; i < _n; i++) {
            if (ord[i] == -1) dfs(dfs, i);
        }
        for (auto& x : ids) {
            x = group_num - 1 - x;
        }
        return {group_num, ids};
    }

    std::vector<std::vector<int>> scc() {
        auto ids = scc_ids();
        int group_num = ids.first;
        std::vector<int> counts(group_num);
        for (auto x : ids.second) counts[x]++;
        std::vector<std::vector<int>> groups(ids.first);
        for (int i = 0; i < group_num; i++) {
            groups[i].reserve(counts[i]);
        }
        for (int i = 0; i < _n; i++) {
            groups[ids.second[i]].push_back(i);
        }
        return groups;
    }

  private:
    int _n;
    struct edge {
        int to;
    };
    std::vector<std::pair<int, edge>> edges;
};

}  // namespace internal

}  // namespace atcoder

#include <cassert>
#include <vector>

namespace atcoder {

struct scc_graph {
  public:
    scc_graph() : internal(0) {}
    scc_graph(int n) : internal(n) {}

    void add_edge(int from, int to) {
        int n = internal.num_vertices();
        assert(0 <= from && from < n);
        assert(0 <= to && to < n);
        internal.add_edge(from, to);
    }

    std::vector<std::vector<int>> scc() { return internal.scc(); }

  private:
    internal::scc_graph internal;
};

}  // namespace atcoder

using namespace atcoder;

#define LB(v, x) (lower_bound(ALL(v), x) - v.begin())
#define UB(v, x) (upper_bound(ALL(v), x) - v.begin())
#define UQnoS(v) v.erase(unique(ALL(v)), v.end())
#define UQ(v) sort(ALL(v)); UQnoS(v)

int main() {
	auto [n] = in<int>();
	auto [a, b, c] = colin<LL, LL, LL>(n);
	
	auto au = a;
	UQ(au);
	const int V = n + SI(au) + 1;
	vector<vector<int>> g(V);
	auto scc = [&] {
		scc_graph scc(V);
		auto add = [&](int a, int b) { g[a].PB(b); scc.add_edge(a, b); };
		inc(i, n) {
			add(n + UB(au, a[i]), i);
			add(i, n + UB(au, b[i] - c[i]));
		}
		inc(i, SI(au)) { add(n + i + 1, n + i); }
		return scc.scc();
	} ();
	
	const LL INF = 1e15;
	const int S = SI(scc);
	vector<int> pos(V);
	vector<LL> val(S);
	inc(i, S) {
		int c = 0;
		RF(e, scc[i]) { pos[e] = i; if(e < n) { val[i] = b[e]; c++; } }
		if(c >= 2) { val[i] = INF; }
	}
	
	vector<LL> ans(n);
	dec(i, S) {
		LL ma = 0;
		RF(v, scc[i]) {
		RF(e, g[v]) {
			if(pos[e] == i) { continue; }
			setmax(ma, val[pos[e]]);
		}
		}
		val[i] += ma;
		setmin(val[i], INF);
		RF(e, scc[i]) { if(e < n) { ans[e] = val[i]; } }
	}
	
	RF(e, ans) { out(e == INF ? "BAN" : to_string(e)); }
}
0