제출 #918958

#제출 시각아이디문제언어결과실행 시간메모리
918958mpb_Team Contest (JOI22_team)C++17
100 / 100
325 ms36176 KiB
/* हर हर महादेव */

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

using ll = int64_t;
using ull = uint64_t;
using ld = long double;

#define int int64_t

using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define mp make_pair
#define fi first
#define se second

template <class T> using vt = vector<T>;
template <class T> using vvt = vt<vt<T>>;
template <class T> using vvvt = vt<vvt<T>>;

#define all(v) (v).begin(), (v).end()
#define si(x) (int)(x).size()
#define pb push_back
#define eb emplace_back

int d4x[4] = {-1, 0, 1, 0};
int d4y[4] = {0, -1, 0, 1};

const ld PI = 3.1415926535897932384626433832795;

template <typename T> using max_heap = priority_queue<T, vt<T>, std::less<T>>;
template <typename T> using min_heap = priority_queue<T, vt<T>, std::greater<T>>;

#define overload4(a, b, c, d, e, ...) e
#define overload3(a, b, c, d, ...) d

#define FOR2(i, a) for (int i = 0; i <= (int)(a); i++)
#define FOR3(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define FOR4(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2)(__VA_ARGS__)

#define ROF2(i, a) for (int i = (int)(a); i >= 0; i--)
#define ROF3(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define ROF4(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define ROF(...) overload4(__VA_ARGS__, ROF4, ROF3, ROF2)(__VA_ARGS__)

template <class, class = void> struct Readable : std::false_type {};
template <class T> struct Readable<T, std::void_t<decltype(std::cin >> std::declval<T&>())>> : std::true_type {};

template <class, class = void> struct Printable : std::false_type {};
template <class T> struct Printable<T, std::void_t<decltype(std::cout << std::declval<T&>())>> : std::true_type {};

template <class, class = void> struct Iterable : std::false_type {};
template <class T> struct Iterable<T, std::void_t<decltype(std::begin(std::declval<T>()))>> : std::true_type {};

template <class, class = void> struct Tuplelike : std::false_type {};
template <class T> struct Tuplelike<T, std::void_t<typename std::tuple_size<T>::type>> : std::true_type {};

struct Scanner {
	void read() {}
	template <class H, class... T> void read(H& h, T&... t) {
		read_single(h);
		read(t...);
	}
	template <typename T> void read_single(T& t) {
		if constexpr (Readable<T>::value) {
			cin >> t;
		} else if constexpr (Tuplelike<T>::value) {
			apply([&](auto&... args) { (read_single(args), ...); }, t);
		} else if constexpr (Iterable<T>::value) {
			for (auto& x : t) read_single(x);
		} else static_assert(Tuplelike<T>::value, "No matching type for read");
	}
} sc;

template <auto& os, bool debug> struct Printer {
	const string sep = debug ? ", " : " ";
	template <class H, class... T> void write(const H& h, const T&... t) {
		write_single(h);
		(void)(..., (write_single(t)));
	}
	template <class H, class... T> void writeln(const H& h, const T&... t) {
		write_single(h);
		(void)(..., (os << sep, write_single(t)));
		os << '\n';
	}
	template <typename T> void write_single(T& t) {
		if constexpr (Printable<T>::value) {
			os << t;
		} else if constexpr (Tuplelike<T>::value) {
			if (debug) os << '(';
			apply([&](const auto&... args) {
				bool fst = true;
				((fst ? (fst = false, write_single(args)) : (os << sep, write_single(args))), ...);
			}, t);
			if (debug) os << ')';
		} else if constexpr (Iterable<T>::value) {
			if (debug) os << '{';
			for (bool fst = true; const auto& x : t) os << (fst ? fst = false, "" : sep), write_single(x);
			if (debug) os << '}';
		} else static_assert(Tuplelike<T>::value, "No matching type for print");
	}
};

Printer<cout, false> pr;
Printer<cerr, true> tr;

template <class H, typename... T>
void read(H& h, T&... t) {
	sc.read(h, t...);
}

template <class H, typename... T>
void write(const H& h, const T&... t) {
	pr.write(h, t...);
}

template <class H, typename... T> 
void print(const H& h, const T&... t) {
	pr.writeln(h, t...);
}

template <class H, typename... T>
void trace(const H& h, const T&... t) {
	tr.writeln(h, t...);
}

#ifdef LOCAL
#define dbg(...) cerr << __func__ << ':' << __LINE__ << " (" << #__VA_ARGS__ << "): ", trace(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

template <class T, class S> bool chmax(T& a, S b) { if (a < b) { a = b; return true; } else return false; }
template <class T, class S> bool chmin(T& a, S b) { if (b < a) { a = b; return true; } else return false; } 

template <class T,class S = ll>
S SUM(const vt<T> &a) {
	return accumulate(all(a), S(0));
}

template <class T>
T MAX(const vt<T> &a) {
	return *max_element(all(a));
}

template <class T>
T MIN(const vt<T> &a) {
	return *min_element(all(a));
}

template <class T> 
void mkuni(vt<T> &v) {
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

template <class T>
vt<int> sortidx(const vt<T> &a) {
	int n = si(a);
	vt<int> idx(n); iota(all(idx),0);
	sort(all(idx),[&](int i,int j){ return a[i] < a[j]; });
	return idx;
}

template <class T>
vt<T> prefsum(const vt<T>& a) {
	int n = si(a);
	vt<T> psum(n + 1);
	for (int i = 1; i <= n; i++) psum[i] = psum[i - 1] + a[i - 1];
	return psum;
}

template <class T>
vt<T> suffsum(const vt<T>& a) {
	int n = si(a);
	vt<T> ssum(n + 1);
	for (int i = n - 1; i >= 0; i--) ssum[i] = ssum[i + 1] + a[i];
	return ssum;
}

template <class T>
T fdiv(T x, T y) {
	assert(y != 0);
	if (y < 0) { x = -x; y = -y; }
	if (x >= 0) return x/y;
	return (x+1)/y - 1;
}

template <class T>
T cdiv(T x, T y) {
	assert(y != 0);
	if (y < 0) { x = -x; y = -y; }
	if (x <= 0) return x/y;
	return (x-1)/y + 1;
}

template <typename T>
T isqrt(T a) {
	T x = T(sqrt(a)) + 2;
	while (1LL * x * x > a) x--;
	return x;
}

void sol() {
	int N; read(N);
	vt<array<int, 3>> B(N); read(B);
	set<pii> x, y, z;
	FOR(i, N - 1) {
		x.emplace(B[i][0], i);
		y.emplace(B[i][1], i);
		z.emplace(B[i][2], i);
	}
	int ans = -1;
	while (min(si(x), min(si(y), si(z))) > 0) {
		auto [xval, id1] = *x.rbegin();
		auto [yval, id2] = *y.rbegin();
		auto [zval, id3] = *z.rbegin();
		bool okx = (B[id1][1] < yval && B[id1][2] < zval);
		bool oky = (B[id2][0] < xval && B[id2][2] < zval);
		bool okz = (B[id3][0] < xval && B[id3][1] < yval);
		if (okx && oky && okz) {
			ans = max(ans, xval + yval + zval);
			break;
		}
		if (!okx) {
			x.erase({xval, id1});
		}
		if (!oky) {
			y.erase({yval, id2});
		} 
		if (!okz) {
			z.erase({zval, id3});
		}
	}
	print(ans);
}

signed main() {
	ios::sync_with_stdio(false), cin.tie(nullptr);
	cout << fixed << setprecision(20);
	int tc = 1; 
	// read(tc);
	while (tc--) sol();
}	

컴파일 시 표준 에러 (stderr) 메시지

team.cpp: In member function 'void Printer<os, debug>::write_single(T&)':
team.cpp:101:26: warning: range-based 'for' loops with initializer only available with '-std=c++2a' or '-std=gnu++2a'
  101 |    for (bool fst = true; const auto& x : t) os << (fst ? fst = false, "" : sep), write_single(x);
      |                          ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...