/*
[ SAMPLE SOURCE CODE FOR "TEAM CONTEST" SUBTASK 5 ]
Algorithm: Please refer to the editorial.
Time Complexity: O(MAX^3)
*/
#include <vector>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
// step #1. read input
cin.tie(0);
ios_base::sync_with_stdio(false);
int N;
cin >> N;
vector<int> X(N), Y(N), Z(N);
for (int i = 0; i < N; i++) {
cin >> X[i] >> Y[i] >> Z[i];
}
// step #2. record in 3D array
int SX = *max_element(X.begin(), X.end()) + 1;
int SY = *max_element(Y.begin(), Y.end()) + 1;
int SZ = *max_element(Z.begin(), Z.end()) + 1;
assert(SX <= 301 && SY <= 301 && SZ <= 301);
vector<vector<vector<bool> > > exists(SX, vector<vector<bool> >(SY, vector<bool>(SZ, false)));
for (int i = 0; i < N; i++) {
exists[X[i]][Y[i]][Z[i]] = true;
}
// step #3. calculate 3D cumulative sum
vector<vector<vector<int> > > sum(SX + 1, vector<vector<int> >(SY + 1, vector<int>(SZ + 1)));
for (int i = 0; i < SX; i++) {
for (int j = 0; j < SY; j++) {
for (int k = 0; k < SZ; k++) {
sum[i + 1][j + 1][k + 1] = (exists[i][j][k] ? 1 : 0);
}
}
}
for (int i = 0; i < SX; i++) {
for (int j = 0; j < SY; j++) {
for (int k = 0; k < SZ; k++) {
sum[i + 1][j + 1][k + 1] += sum[i][j + 1][k + 1];
}
}
}
for (int i = 0; i < SX; i++) {
for (int j = 0; j < SY; j++) {
for (int k = 0; k < SZ; k++) {
sum[i + 1][j + 1][k + 1] += sum[i + 1][j][k + 1];
}
}
}
for (int i = 0; i < SX; i++) {
for (int j = 0; j < SY; j++) {
for (int k = 0; k < SZ; k++) {
sum[i + 1][j + 1][k + 1] += sum[i + 1][j + 1][k];
}
}
}
// step #4. brute force
int answer = -1;
for (int x = 1; x < SX; x++) {
for (int y = 1; y < SY; y++) {
for (int z = 1; z < SZ; z++) {
int sumx = sum[x + 1][y][z] - sum[x][y][z];
int sumy = sum[x][y + 1][z] - sum[x][y][z];
int sumz = sum[x][y][z + 1] - sum[x][y][z];
if (sumx >= 1 && sumy >= 1 && sumz >= 1) {
answer = x + y + z;
}
}
}
}
// step #5. output the answer
cout << answer << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
236 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
236 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
41 ms |
2088 KB |
Output is correct |
12 |
Correct |
28 ms |
1516 KB |
Output is correct |
13 |
Correct |
25 ms |
1784 KB |
Output is correct |
14 |
Correct |
32 ms |
2080 KB |
Output is correct |
15 |
Correct |
27 ms |
2004 KB |
Output is correct |
16 |
Correct |
25 ms |
2084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
41 ms |
2088 KB |
Output is correct |
12 |
Correct |
28 ms |
1516 KB |
Output is correct |
13 |
Correct |
25 ms |
1784 KB |
Output is correct |
14 |
Correct |
32 ms |
2080 KB |
Output is correct |
15 |
Correct |
27 ms |
2004 KB |
Output is correct |
16 |
Correct |
25 ms |
2084 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
40 ms |
2080 KB |
Output is correct |
23 |
Correct |
25 ms |
2048 KB |
Output is correct |
24 |
Correct |
33 ms |
1596 KB |
Output is correct |
25 |
Correct |
35 ms |
2088 KB |
Output is correct |
26 |
Correct |
35 ms |
2088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
41 ms |
2088 KB |
Output is correct |
12 |
Correct |
28 ms |
1516 KB |
Output is correct |
13 |
Correct |
25 ms |
1784 KB |
Output is correct |
14 |
Correct |
32 ms |
2080 KB |
Output is correct |
15 |
Correct |
27 ms |
2004 KB |
Output is correct |
16 |
Correct |
25 ms |
2084 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
40 ms |
2080 KB |
Output is correct |
23 |
Correct |
25 ms |
2048 KB |
Output is correct |
24 |
Correct |
33 ms |
1596 KB |
Output is correct |
25 |
Correct |
35 ms |
2088 KB |
Output is correct |
26 |
Correct |
35 ms |
2088 KB |
Output is correct |
27 |
Correct |
233 ms |
112924 KB |
Output is correct |
28 |
Correct |
19 ms |
10156 KB |
Output is correct |
29 |
Correct |
13 ms |
5460 KB |
Output is correct |
30 |
Correct |
13 ms |
5460 KB |
Output is correct |
31 |
Correct |
250 ms |
119200 KB |
Output is correct |
32 |
Correct |
231 ms |
119160 KB |
Output is correct |
33 |
Correct |
254 ms |
119156 KB |
Output is correct |
34 |
Correct |
272 ms |
120852 KB |
Output is correct |
35 |
Correct |
251 ms |
118416 KB |
Output is correct |
36 |
Correct |
322 ms |
111264 KB |
Output is correct |
37 |
Correct |
295 ms |
120916 KB |
Output is correct |
38 |
Correct |
96 ms |
25944 KB |
Output is correct |
39 |
Correct |
275 ms |
120216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
41 ms |
2088 KB |
Output is correct |
12 |
Correct |
28 ms |
1516 KB |
Output is correct |
13 |
Correct |
25 ms |
1784 KB |
Output is correct |
14 |
Correct |
32 ms |
2080 KB |
Output is correct |
15 |
Correct |
27 ms |
2004 KB |
Output is correct |
16 |
Correct |
25 ms |
2084 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
40 ms |
2080 KB |
Output is correct |
23 |
Correct |
25 ms |
2048 KB |
Output is correct |
24 |
Correct |
33 ms |
1596 KB |
Output is correct |
25 |
Correct |
35 ms |
2088 KB |
Output is correct |
26 |
Correct |
35 ms |
2088 KB |
Output is correct |
27 |
Correct |
233 ms |
112924 KB |
Output is correct |
28 |
Correct |
19 ms |
10156 KB |
Output is correct |
29 |
Correct |
13 ms |
5460 KB |
Output is correct |
30 |
Correct |
13 ms |
5460 KB |
Output is correct |
31 |
Correct |
250 ms |
119200 KB |
Output is correct |
32 |
Correct |
231 ms |
119160 KB |
Output is correct |
33 |
Correct |
254 ms |
119156 KB |
Output is correct |
34 |
Correct |
272 ms |
120852 KB |
Output is correct |
35 |
Correct |
251 ms |
118416 KB |
Output is correct |
36 |
Correct |
322 ms |
111264 KB |
Output is correct |
37 |
Correct |
295 ms |
120916 KB |
Output is correct |
38 |
Correct |
96 ms |
25944 KB |
Output is correct |
39 |
Correct |
275 ms |
120216 KB |
Output is correct |
40 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 6 |
41 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
236 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
15 |
Halted |
0 ms |
0 KB |
- |