답안 #987892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
987892 2024-05-23T18:40:02 Z Antekb Team Contest (JOI22_team) C++17
100 / 100
952 ms 28872 KB
#include<bits/stdc++.h>
 
#pragma GCC optimize("Ofast")
//#pragma GCC optimize("trapv")
 
#define st first
#define nd second
#define pb push_back
#define eb emplace_back
#define pp(x) pop_back(x)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define rev(x) reverse(all(x))
#define sor(x) sort(all(x))
#define sz(x) (int)(x).size()
#define rsz(x) resize(x)
 
using namespace std;
 
///~~~~~~~~~~~~~~~~~~~~~~~~~~
 
template <typename H, typename T> 
ostream& operator<<(ostream& os, pair<H, T> m){
	return os <<"("<< m.st<<", "<<m.nd<<")";
}
template <typename H> 
ostream& operator<<(ostream& os, vector<H> V){
	os<<"{";
	for(int i=0; i<V.size(); i++){
		if(i)os<<" ";
		os<<V[i];
	}
	os<<"}";
	return os;
}
 
void debug(){cerr<<"\n";}
template <typename H, typename... T>
void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);}
#define deb(x...) cerr<<#x<<" = ";debug(x);
//#define deb(x...) ;
 
///~~~~~~~~~~~~~~~~~~~~~~~~~
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii > vii;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef string str;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

 
#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=1<<20, INF=1e9+5, mod2=1e9+7, mod=998244353;

struct modint{
	int n=0;
	modint(){}
	modint(ll x){
		n=x%mod;
		if(n<0)n+=mod;
	}
	operator int(){
		return n;
	}
	modint operator+(modint a){a.n = n+a.n; if(a.n>=mod)a.n-=mod;return a;}
	modint operator+=(modint a){return (*this)=(*this)+a;}
	modint operator-(modint a){a.n = n-a.n; if(a.n<0)a.n+=mod;return a;}
	modint operator-=(modint a){return (*this)=(*this)-a;}
	modint operator*(modint a){a.n = (n*1ll*a.n)%mod; return a;}
	modint operator*=(modint a){return (*this)=(*this)*a;}
	modint por(const ll &m)const{
		modint a(1);
		if(m==0)return a;
		if(m==1)return (*this);
		a=por(m/2);
		a*=a;
		return a*(por(m&1));
	}
	modint odw(){
		return por((ll)mod-2);
	}
	modint operator/(modint a){return (*this)*a.odw();}
	modint operator/=(modint a){return (*this)=(*this)/a;}
	bool operator==(modint a){return a.n==n;}
	friend ostream& operator<<(ostream& os, modint m) {
		return os << m.n; 
	}
};
modint fact[N], fact2[N];
typedef vector<modint> vm;
void factinit(){
    fact[0]=1;
    for(int i=1; i<N; i++){
        fact[i]=(fact[i-1]*modint(i))%mod;
    }
    fact2[N-1]=fact[N-1].odw();
    for(int i=N-2; i>=0; i--){
    	fact2[i]=(fact2[i+1]*modint(i+1))%mod;
    }
}
modint npok(int _n, int _k){
    return fact[_n]*fact2[_k]*fact2[_n-_k];
}
int X[N], Y[N], Z[N];
vi Vx, Vy, Vz;
int solve(vi A, vi B, vi C){
	while(A.size() && B.size() && C.size()){
		bool to_break=1;
		while(A.size() && (Y[A.back()]>=Y[B.back()] || Z[A.back()]>=Z[C.back()]))A.pp(), to_break=0;
		if(!A.size())break;
		while(B.size() && (X[B.back()]>=X[A.back()] || Z[B.back()]>=Z[C.back()]))B.pp(), to_break=0;
		if(!B.size())break;
		while(C.size() && (Y[C.back()]>=Y[B.back()] || X[C.back()]>=X[A.back()]))C.pp(), to_break=0;
		if(!C.size())break;
		if(to_break)break;
	}
	if(A.size() && B.size() && C.size())return X[A.back()]+Y[B.back()]+Z[C.back()];
	return -1;
}
int main(){
	//factinit();
	BOOST;
	int n;
	cin>>n;
	for(int i=0; i<n; i++){
		cin>>X[i]>>Y[i]>>Z[i];
	}
	Vx.resize(n);
	iota(all(Vx), 0);
	Vy.resize(n);
	iota(all(Vy), 0);
	Vz.resize(n);
	iota(all(Vz), 0);
	sort(all(Vx), [](int a ,int b){return X[a]<X[b];});
	sort(all(Vy), [](int a ,int b){return Y[a]<Y[b];});
	sort(all(Vz), [](int a ,int b){return Z[a]<Z[b];});
	int ans=-1;
	for(int i=0; i<150; i++){
		vi typ(n);
		for(int &j:typ)j=rng()%3;
		vi A, B, C;
		for(int j:Vx)if(typ[j]==0)A.pb(j);
		for(int j:Vy)if(typ[j]==1)B.pb(j);
		for(int j:Vz)if(typ[j]==2)C.pb(j);
		ans=max(ans, solve(A, B, C));
	}
	cout<<ans<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14428 KB Output is correct
2 Correct 7 ms 14428 KB Output is correct
3 Correct 7 ms 14428 KB Output is correct
4 Correct 8 ms 14428 KB Output is correct
5 Correct 7 ms 14428 KB Output is correct
6 Correct 7 ms 14648 KB Output is correct
7 Correct 8 ms 14428 KB Output is correct
8 Correct 6 ms 14452 KB Output is correct
9 Correct 7 ms 14644 KB Output is correct
10 Correct 6 ms 14656 KB Output is correct
11 Correct 7 ms 14616 KB Output is correct
12 Correct 7 ms 14428 KB Output is correct
13 Correct 8 ms 14428 KB Output is correct
14 Correct 8 ms 14520 KB Output is correct
15 Correct 8 ms 14428 KB Output is correct
16 Correct 9 ms 14428 KB Output is correct
17 Correct 9 ms 14428 KB Output is correct
18 Correct 8 ms 14428 KB Output is correct
19 Correct 10 ms 14428 KB Output is correct
20 Correct 8 ms 14428 KB Output is correct
21 Correct 9 ms 14428 KB Output is correct
22 Correct 8 ms 14428 KB Output is correct
23 Correct 9 ms 14424 KB Output is correct
24 Correct 8 ms 14428 KB Output is correct
25 Correct 9 ms 14604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14428 KB Output is correct
2 Correct 7 ms 14428 KB Output is correct
3 Correct 7 ms 14428 KB Output is correct
4 Correct 8 ms 14428 KB Output is correct
5 Correct 7 ms 14428 KB Output is correct
6 Correct 7 ms 14648 KB Output is correct
7 Correct 8 ms 14428 KB Output is correct
8 Correct 6 ms 14452 KB Output is correct
9 Correct 7 ms 14644 KB Output is correct
10 Correct 6 ms 14656 KB Output is correct
11 Correct 7 ms 14616 KB Output is correct
12 Correct 7 ms 14428 KB Output is correct
13 Correct 8 ms 14428 KB Output is correct
14 Correct 8 ms 14520 KB Output is correct
15 Correct 8 ms 14428 KB Output is correct
16 Correct 9 ms 14428 KB Output is correct
17 Correct 9 ms 14428 KB Output is correct
18 Correct 8 ms 14428 KB Output is correct
19 Correct 10 ms 14428 KB Output is correct
20 Correct 8 ms 14428 KB Output is correct
21 Correct 9 ms 14428 KB Output is correct
22 Correct 8 ms 14428 KB Output is correct
23 Correct 9 ms 14424 KB Output is correct
24 Correct 8 ms 14428 KB Output is correct
25 Correct 9 ms 14604 KB Output is correct
26 Correct 20 ms 14684 KB Output is correct
27 Correct 22 ms 14680 KB Output is correct
28 Correct 23 ms 14772 KB Output is correct
29 Correct 27 ms 14868 KB Output is correct
30 Correct 18 ms 14768 KB Output is correct
31 Correct 21 ms 14684 KB Output is correct
32 Correct 23 ms 14684 KB Output is correct
33 Correct 25 ms 14876 KB Output is correct
34 Correct 25 ms 14888 KB Output is correct
35 Correct 10 ms 14652 KB Output is correct
36 Correct 11 ms 14680 KB Output is correct
37 Correct 23 ms 14712 KB Output is correct
38 Correct 24 ms 14824 KB Output is correct
39 Correct 13 ms 14680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14428 KB Output is correct
2 Correct 7 ms 14576 KB Output is correct
3 Correct 7 ms 14424 KB Output is correct
4 Correct 6 ms 14644 KB Output is correct
5 Correct 7 ms 14428 KB Output is correct
6 Correct 6 ms 14428 KB Output is correct
7 Correct 7 ms 14424 KB Output is correct
8 Correct 7 ms 14428 KB Output is correct
9 Correct 6 ms 14424 KB Output is correct
10 Correct 6 ms 14776 KB Output is correct
11 Correct 568 ms 25396 KB Output is correct
12 Correct 442 ms 24224 KB Output is correct
13 Correct 467 ms 24488 KB Output is correct
14 Correct 642 ms 25588 KB Output is correct
15 Correct 584 ms 25448 KB Output is correct
16 Correct 572 ms 25372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14428 KB Output is correct
2 Correct 7 ms 14576 KB Output is correct
3 Correct 7 ms 14424 KB Output is correct
4 Correct 6 ms 14644 KB Output is correct
5 Correct 7 ms 14428 KB Output is correct
6 Correct 6 ms 14428 KB Output is correct
7 Correct 7 ms 14424 KB Output is correct
8 Correct 7 ms 14428 KB Output is correct
9 Correct 6 ms 14424 KB Output is correct
10 Correct 6 ms 14776 KB Output is correct
11 Correct 568 ms 25396 KB Output is correct
12 Correct 442 ms 24224 KB Output is correct
13 Correct 467 ms 24488 KB Output is correct
14 Correct 642 ms 25588 KB Output is correct
15 Correct 584 ms 25448 KB Output is correct
16 Correct 572 ms 25372 KB Output is correct
17 Correct 7 ms 14684 KB Output is correct
18 Correct 8 ms 14428 KB Output is correct
19 Correct 7 ms 14428 KB Output is correct
20 Correct 8 ms 14428 KB Output is correct
21 Correct 13 ms 14684 KB Output is correct
22 Correct 602 ms 25800 KB Output is correct
23 Correct 593 ms 25256 KB Output is correct
24 Correct 529 ms 24572 KB Output is correct
25 Correct 706 ms 25404 KB Output is correct
26 Correct 575 ms 25396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14428 KB Output is correct
2 Correct 7 ms 14576 KB Output is correct
3 Correct 7 ms 14424 KB Output is correct
4 Correct 6 ms 14644 KB Output is correct
5 Correct 7 ms 14428 KB Output is correct
6 Correct 6 ms 14428 KB Output is correct
7 Correct 7 ms 14424 KB Output is correct
8 Correct 7 ms 14428 KB Output is correct
9 Correct 6 ms 14424 KB Output is correct
10 Correct 6 ms 14776 KB Output is correct
11 Correct 568 ms 25396 KB Output is correct
12 Correct 442 ms 24224 KB Output is correct
13 Correct 467 ms 24488 KB Output is correct
14 Correct 642 ms 25588 KB Output is correct
15 Correct 584 ms 25448 KB Output is correct
16 Correct 572 ms 25372 KB Output is correct
17 Correct 7 ms 14684 KB Output is correct
18 Correct 8 ms 14428 KB Output is correct
19 Correct 7 ms 14428 KB Output is correct
20 Correct 8 ms 14428 KB Output is correct
21 Correct 13 ms 14684 KB Output is correct
22 Correct 602 ms 25800 KB Output is correct
23 Correct 593 ms 25256 KB Output is correct
24 Correct 529 ms 24572 KB Output is correct
25 Correct 706 ms 25404 KB Output is correct
26 Correct 575 ms 25396 KB Output is correct
27 Correct 8 ms 14428 KB Output is correct
28 Correct 8 ms 14428 KB Output is correct
29 Correct 8 ms 14428 KB Output is correct
30 Correct 8 ms 14428 KB Output is correct
31 Correct 24 ms 14684 KB Output is correct
32 Correct 10 ms 14680 KB Output is correct
33 Correct 11 ms 14684 KB Output is correct
34 Correct 590 ms 25484 KB Output is correct
35 Correct 644 ms 25436 KB Output is correct
36 Correct 683 ms 25860 KB Output is correct
37 Correct 769 ms 25788 KB Output is correct
38 Correct 613 ms 25528 KB Output is correct
39 Correct 342 ms 23944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14428 KB Output is correct
2 Correct 7 ms 14576 KB Output is correct
3 Correct 7 ms 14424 KB Output is correct
4 Correct 6 ms 14644 KB Output is correct
5 Correct 7 ms 14428 KB Output is correct
6 Correct 6 ms 14428 KB Output is correct
7 Correct 7 ms 14424 KB Output is correct
8 Correct 7 ms 14428 KB Output is correct
9 Correct 6 ms 14424 KB Output is correct
10 Correct 6 ms 14776 KB Output is correct
11 Correct 568 ms 25396 KB Output is correct
12 Correct 442 ms 24224 KB Output is correct
13 Correct 467 ms 24488 KB Output is correct
14 Correct 642 ms 25588 KB Output is correct
15 Correct 584 ms 25448 KB Output is correct
16 Correct 572 ms 25372 KB Output is correct
17 Correct 7 ms 14684 KB Output is correct
18 Correct 8 ms 14428 KB Output is correct
19 Correct 7 ms 14428 KB Output is correct
20 Correct 8 ms 14428 KB Output is correct
21 Correct 13 ms 14684 KB Output is correct
22 Correct 602 ms 25800 KB Output is correct
23 Correct 593 ms 25256 KB Output is correct
24 Correct 529 ms 24572 KB Output is correct
25 Correct 706 ms 25404 KB Output is correct
26 Correct 575 ms 25396 KB Output is correct
27 Correct 8 ms 14428 KB Output is correct
28 Correct 8 ms 14428 KB Output is correct
29 Correct 8 ms 14428 KB Output is correct
30 Correct 8 ms 14428 KB Output is correct
31 Correct 24 ms 14684 KB Output is correct
32 Correct 10 ms 14680 KB Output is correct
33 Correct 11 ms 14684 KB Output is correct
34 Correct 590 ms 25484 KB Output is correct
35 Correct 644 ms 25436 KB Output is correct
36 Correct 683 ms 25860 KB Output is correct
37 Correct 769 ms 25788 KB Output is correct
38 Correct 613 ms 25528 KB Output is correct
39 Correct 342 ms 23944 KB Output is correct
40 Correct 17 ms 14652 KB Output is correct
41 Correct 22 ms 14892 KB Output is correct
42 Correct 26 ms 14776 KB Output is correct
43 Correct 23 ms 14680 KB Output is correct
44 Correct 635 ms 25888 KB Output is correct
45 Correct 799 ms 25836 KB Output is correct
46 Correct 740 ms 25880 KB Output is correct
47 Correct 793 ms 25844 KB Output is correct
48 Correct 593 ms 25948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14428 KB Output is correct
2 Correct 7 ms 14428 KB Output is correct
3 Correct 7 ms 14428 KB Output is correct
4 Correct 8 ms 14428 KB Output is correct
5 Correct 7 ms 14428 KB Output is correct
6 Correct 7 ms 14648 KB Output is correct
7 Correct 8 ms 14428 KB Output is correct
8 Correct 6 ms 14452 KB Output is correct
9 Correct 7 ms 14644 KB Output is correct
10 Correct 6 ms 14656 KB Output is correct
11 Correct 7 ms 14616 KB Output is correct
12 Correct 7 ms 14428 KB Output is correct
13 Correct 8 ms 14428 KB Output is correct
14 Correct 8 ms 14520 KB Output is correct
15 Correct 8 ms 14428 KB Output is correct
16 Correct 9 ms 14428 KB Output is correct
17 Correct 9 ms 14428 KB Output is correct
18 Correct 8 ms 14428 KB Output is correct
19 Correct 10 ms 14428 KB Output is correct
20 Correct 8 ms 14428 KB Output is correct
21 Correct 9 ms 14428 KB Output is correct
22 Correct 8 ms 14428 KB Output is correct
23 Correct 9 ms 14424 KB Output is correct
24 Correct 8 ms 14428 KB Output is correct
25 Correct 9 ms 14604 KB Output is correct
26 Correct 20 ms 14684 KB Output is correct
27 Correct 22 ms 14680 KB Output is correct
28 Correct 23 ms 14772 KB Output is correct
29 Correct 27 ms 14868 KB Output is correct
30 Correct 18 ms 14768 KB Output is correct
31 Correct 21 ms 14684 KB Output is correct
32 Correct 23 ms 14684 KB Output is correct
33 Correct 25 ms 14876 KB Output is correct
34 Correct 25 ms 14888 KB Output is correct
35 Correct 10 ms 14652 KB Output is correct
36 Correct 11 ms 14680 KB Output is correct
37 Correct 23 ms 14712 KB Output is correct
38 Correct 24 ms 14824 KB Output is correct
39 Correct 13 ms 14680 KB Output is correct
40 Correct 6 ms 14428 KB Output is correct
41 Correct 7 ms 14576 KB Output is correct
42 Correct 7 ms 14424 KB Output is correct
43 Correct 6 ms 14644 KB Output is correct
44 Correct 7 ms 14428 KB Output is correct
45 Correct 6 ms 14428 KB Output is correct
46 Correct 7 ms 14424 KB Output is correct
47 Correct 7 ms 14428 KB Output is correct
48 Correct 6 ms 14424 KB Output is correct
49 Correct 6 ms 14776 KB Output is correct
50 Correct 568 ms 25396 KB Output is correct
51 Correct 442 ms 24224 KB Output is correct
52 Correct 467 ms 24488 KB Output is correct
53 Correct 642 ms 25588 KB Output is correct
54 Correct 584 ms 25448 KB Output is correct
55 Correct 572 ms 25372 KB Output is correct
56 Correct 7 ms 14684 KB Output is correct
57 Correct 8 ms 14428 KB Output is correct
58 Correct 7 ms 14428 KB Output is correct
59 Correct 8 ms 14428 KB Output is correct
60 Correct 13 ms 14684 KB Output is correct
61 Correct 602 ms 25800 KB Output is correct
62 Correct 593 ms 25256 KB Output is correct
63 Correct 529 ms 24572 KB Output is correct
64 Correct 706 ms 25404 KB Output is correct
65 Correct 575 ms 25396 KB Output is correct
66 Correct 8 ms 14428 KB Output is correct
67 Correct 8 ms 14428 KB Output is correct
68 Correct 8 ms 14428 KB Output is correct
69 Correct 8 ms 14428 KB Output is correct
70 Correct 24 ms 14684 KB Output is correct
71 Correct 10 ms 14680 KB Output is correct
72 Correct 11 ms 14684 KB Output is correct
73 Correct 590 ms 25484 KB Output is correct
74 Correct 644 ms 25436 KB Output is correct
75 Correct 683 ms 25860 KB Output is correct
76 Correct 769 ms 25788 KB Output is correct
77 Correct 613 ms 25528 KB Output is correct
78 Correct 342 ms 23944 KB Output is correct
79 Correct 17 ms 14652 KB Output is correct
80 Correct 22 ms 14892 KB Output is correct
81 Correct 26 ms 14776 KB Output is correct
82 Correct 23 ms 14680 KB Output is correct
83 Correct 635 ms 25888 KB Output is correct
84 Correct 799 ms 25836 KB Output is correct
85 Correct 740 ms 25880 KB Output is correct
86 Correct 793 ms 25844 KB Output is correct
87 Correct 593 ms 25948 KB Output is correct
88 Correct 658 ms 28872 KB Output is correct
89 Correct 839 ms 28700 KB Output is correct
90 Correct 689 ms 28504 KB Output is correct
91 Correct 952 ms 28676 KB Output is correct
92 Correct 720 ms 27364 KB Output is correct
93 Correct 854 ms 27528 KB Output is correct
94 Correct 841 ms 27460 KB Output is correct
95 Correct 615 ms 28428 KB Output is correct
96 Correct 823 ms 28712 KB Output is correct
97 Correct 551 ms 28608 KB Output is correct
98 Correct 616 ms 27108 KB Output is correct
99 Correct 678 ms 27164 KB Output is correct