QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#798275#168. Cube DividingCarroT1212WA 566ms41860kbC++141.9kb2024-12-04 10:59:172024-12-04 10:59:17

Judging History

This is the latest submission verdict.

  • [2024-12-04 10:59:17]
  • Judged
  • Verdict: WA
  • Time: 566ms
  • Memory: 41860kb
  • [2024-12-04 10:59:17]
  • Submitted

answer

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define go(xx,yy,zz) for(ll x=xx-1;x<=xx+1;x++)for(ll y=yy-1;y<=yy+1;y++)for(ll z=zz-1;z<=zz+1;z++)
using namespace std; bool MEM;
using ll=long long; using ld=long double;
using pii=pair<int,int>; using pll=pair<ll,ll>;
const int I=1e9;
const ll J=1e18,K=1e6+7,N=3e5+7;
ll n,a,b,c,vis[N],ans,flg;
struct nod {
	ll x,y,z;
	bool operator == (const nod &b) const { return x==b.x&&y==b.y&&z==b.z; }
	bool operator < (const nod &b) const { return x!=b.x?x<b.x:y!=b.y?y<b.y:z<b.z; }
} d[N];
map<nod,ll> mp;
map<nod,ll> pm;
vector<ll> v;
bool chk(ll x,ll y,ll z) { return -2<=x&&x<=a+1&&-2<=y&&y<=b+1&&-2<=z&&z<=c+1; }
void dfs(nod p) {
	pm.erase(p);
	ll x=p.x,y=p.y,z=p.z;
	flg|=0<=x&&x<a&&0<=y&&y<b&&0<=z&&z<c;
	#define goo(xx,yy,zz) if (chk(xx,yy,zz)&&pm.count({xx,yy,zz})) dfs({xx,yy,zz});
	goo(x-1,y,z) goo(x+1,y,z)
	goo(x,y-1,z) goo(x,y+1,z)
	goo(x,y,z-1) goo(x,y,z+1)
}
void solve(ll o) {
	queue<ll> q;
	q.push(o),vis[o]=1;
	while (!q.empty()) {
		ll p=q.front(); q.pop();
		go(d[p].x,d[p].y,d[p].z) if (chk(x,y,z)) {
			if (mp.count({x,y,z})) {
				ll t=mp[{x,y,z}];
				if (!vis[t]) v.pb(t),vis[t]=1,q.push(t);
			}
			else pm[{x,y,z}]=1;
		}
	}
	ans--;
	while (pm.size()) flg=0,dfs(pm.begin()->fi),ans+=flg;
}
void mian() {
	scanf("%lld%lld%lld%lld",&a,&b,&c,&n),ans=1;
	for (ll i=1;i<=n;i++) scanf("%lld%lld%lld",&d[i].x,&d[i].y,&d[i].z);
	ll nn=n;
	for (ll i=1;i<=nn;i++)
		d[++n]={-1,d[i].y,d[i].z},d[++n]={a,d[i].y,d[i].z},
		d[++n]={d[i].x,-1,d[i].z},d[++n]={d[i].x,b,d[i].z},
		d[++n]={d[i].x,d[i].y,-1},d[++n]={d[i].x,d[i].y,c};
	sort(d+1,d+n+1),n=unique(d+1,d+n+1)-1-d;
	for (ll i=1;i<=n;i++) mp[d[i]]=i;
	for (ll i=1;i<=n;i++) if (!vis[i]) solve(i);
	cout<<ans;
}
bool ORY; int main() {
//	while (1)
//	int t; for (scanf("%d",&t);t--;)
	mian();
	cerr<<"\n"<<abs(&MEM-&ORY)/1048576<<"MB";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5756kb

input:

2 2 2 4
0 0 0
1 1 0
1 0 1
0 1 1

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 1ms
memory: 5768kb

input:

3 3 3 1
1 1 1

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 1ms
memory: 6032kb

input:

1 1 3 2
0 0 0
0 0 2

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 84ms
memory: 20548kb

input:

8 60 66 8004
4 49 31
0 38 42
0 45 22
1 19 23
1 36 47
6 9 15
7 55 18
4 24 51
4 34 31
0 31 64
5 24 23
0 48 34
6 30 12
6 41 22
3 6 51
3 43 34
4 49 39
5 31 5
3 36 63
5 37 21
4 11 55
6 53 41
6 51 56
6 42 9
4 59 55
3 30 49
5 15 32
3 59 64
5 7 32
2 42 60
3 0 27
7 5 41
3 34 45
5 39 57
3 24 36
0 16 13
1 55 3...

output:

15

result:

ok single line: '15'

Test #5:

score: 0
Accepted
time: 156ms
memory: 30548kb

input:

97 26 86 6966
67 4 0
63 2 45
30 1 66
37 12 70
54 10 50
61 13 14
82 10 29
76 20 42
66 14 45
8 19 65
2 0 63
42 19 24
11 21 23
65 2 56
65 24 61
33 15 17
51 0 26
2 19 51
7 21 38
53 15 57
73 13 42
38 13 10
78 22 52
83 15 14
68 13 55
50 5 62
70 0 17
56 2 84
93 13 29
44 6 40
58 13 1
15 17 66
38 21 59
2 16 ...

output:

1

result:

ok single line: '1'

Test #6:

score: 0
Accepted
time: 83ms
memory: 14624kb

input:

80 33 9 14465
35 15 4
24 9 4
59 30 8
18 15 6
64 2 4
54 5 6
49 29 1
38 12 8
1 5 4
29 23 0
70 25 5
26 15 2
11 18 7
47 30 5
37 30 3
54 29 1
73 23 5
22 31 8
31 28 7
4 11 2
65 10 8
64 15 1
25 31 7
58 2 5
72 2 2
49 15 3
50 18 5
36 22 1
19 21 7
29 31 6
31 25 0
54 30 3
15 24 1
7 18 7
38 6 7
57 20 8
32 16 0
...

output:

857

result:

ok single line: '857'

Test #7:

score: 0
Accepted
time: 163ms
memory: 29052kb

input:

52 78 36 9942
35 64 32
40 33 27
9 69 5
24 3 19
46 30 5
40 11 5
47 28 13
15 56 30
1 1 2
43 24 35
48 31 33
49 13 31
35 36 2
25 45 0
14 67 26
30 52 23
1 45 13
3 47 0
7 40 28
21 0 4
19 64 8
32 26 17
19 29 12
7 8 24
42 3 15
21 39 11
35 41 13
47 28 22
18 5 18
40 67 23
36 75 12
35 21 10
16 59 0
25 13 10
51...

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 283ms
memory: 39420kb

input:

51 84 87 15969
40 48 55
26 8 25
36 80 48
40 13 16
32 68 60
19 2 45
16 38 38
49 22 70
36 66 76
21 51 86
24 9 80
50 78 36
9 78 50
9 35 2
49 63 83
16 52 0
50 58 76
47 43 66
37 3 71
14 70 86
49 48 66
39 74 80
34 16 24
9 34 54
49 65 54
16 77 17
18 73 84
35 61 45
39 16 38
21 2 46
48 5 7
22 17 64
14 35 38
...

output:

1

result:

ok single line: '1'

Test #9:

score: 0
Accepted
time: 252ms
memory: 41860kb

input:

58 55 66 17448
53 12 4
23 49 53
53 8 55
57 12 42
51 47 34
20 45 24
48 37 2
0 24 28
33 4 38
1 26 56
57 17 31
6 14 31
36 36 26
33 0 40
24 1 50
37 0 45
15 32 59
40 19 31
32 54 50
29 9 38
32 42 40
21 47 21
46 48 65
21 13 46
50 17 37
5 47 19
56 44 41
15 20 44
10 43 2
37 2 7
39 11 7
34 10 55
8 46 24
18 41...

output:

1

result:

ok single line: '1'

Test #10:

score: 0
Accepted
time: 91ms
memory: 16316kb

input:

31 49 22 14484
7 46 11
10 29 1
15 0 8
11 10 3
14 9 5
22 3 4
9 27 18
13 40 13
28 20 7
4 28 12
4 44 21
15 10 17
4 8 12
17 25 15
30 11 0
24 8 6
24 37 2
1 4 6
8 47 16
26 33 14
3 26 14
11 24 13
19 41 15
13 10 19
24 38 12
30 28 13
12 0 9
5 4 6
18 16 20
13 20 13
29 8 21
27 2 18
19 2 19
23 41 7
25 32 2
25 1...

output:

205

result:

ok single line: '205'

Test #11:

score: 0
Accepted
time: 140ms
memory: 28720kb

input:

65 36 42 8374
5 21 22
44 30 18
50 1 35
16 34 37
54 30 4
28 33 8
12 31 24
32 28 15
45 11 27
12 34 15
36 10 6
52 34 7
37 25 32
6 5 3
53 17 32
17 25 6
45 34 13
5 13 41
56 24 27
45 11 9
15 28 0
42 4 14
50 30 40
61 0 26
51 4 31
59 13 1
39 5 12
11 28 9
55 19 25
12 18 14
58 35 4
14 3 41
59 5 34
24 22 22
30...

output:

1

result:

ok single line: '1'

Test #12:

score: 0
Accepted
time: 82ms
memory: 25084kb

input:

24 49 106 3104
7 32 74
19 29 65
8 31 71
10 7 74
0 21 49
16 6 100
11 5 97
6 5 43
21 9 88
6 11 22
16 38 40
4 30 14
2 27 101
17 8 84
12 44 56
6 21 4
19 42 0
10 29 71
1 17 92
16 15 76
0 43 43
23 47 99
14 27 64
17 47 19
0 8 35
19 26 39
23 30 74
13 30 35
19 37 49
4 1 87
12 17 50
22 30 2
14 3 38
23 10 105
...

output:

1

result:

ok single line: '1'

Test #13:

score: 0
Accepted
time: 125ms
memory: 33308kb

input:

14 92 57 6904
10 47 23
12 77 13
12 34 39
4 79 23
3 60 39
2 42 20
2 25 3
2 33 52
6 32 3
2 72 13
2 88 29
6 29 35
13 27 49
1 44 15
0 56 36
4 18 10
2 35 22
5 11 33
6 4 29
8 8 43
7 73 28
2 9 45
6 27 43
0 71 29
9 22 46
8 1 23
3 64 12
12 89 1
11 41 56
12 25 51
13 21 52
10 85 41
6 70 44
3 14 1
8 2 26
9 35 4...

output:

2

result:

ok single line: '2'

Test #14:

score: 0
Accepted
time: 400ms
memory: 17116kb

input:

883659 73120 315984 13620
356561 25749 95618
703272 39911 262803
491727 19022 72760
70333 17287 153234
97287 33099 183707
824073 26403 296847
810501 53197 224664
751333 40590 147652
477481 66750 310506
311528 62992 8676
89763 58901 253720
698886 31886 41966
514225 56832 252776
792753 51105 160521
14...

output:

1

result:

ok single line: '1'

Test #15:

score: 0
Accepted
time: 528ms
memory: 20096kb

input:

324302 445977 917979 17452
125069 220918 216779
35630 1072 403457
231031 437649 901553
194958 244880 545564
89610 119440 532432
160581 30197 164902
130088 341024 110278
308124 80539 631170
162759 337540 398836
170540 353858 134156
267624 351491 330475
102540 254576 379531
271164 288911 455726
145606...

output:

1

result:

ok single line: '1'

Test #16:

score: 0
Accepted
time: 566ms
memory: 20436kb

input:

476922 692806 26199 18828
393771 546899 10840
440983 606547 15031
389272 266105 24628
462562 204800 11320
171370 222866 21872
419614 621262 22489
389347 112725 22209
463156 346970 19224
350989 513377 18930
192024 644329 15346
163295 316179 15116
212996 683052 18780
206573 23761 22973
407692 28936 58...

output:

1

result:

ok single line: '1'

Test #17:

score: 0
Accepted
time: 263ms
memory: 13844kb

input:

34295 450436 484714 9110
30469 162145 376280
28325 374106 467569
486 36256 192154
13098 328175 333483
21107 349376 262223
17979 370500 197997
6894 174652 402872
10792 368389 305356
27697 296425 33743
20488 418859 185348
2607 156097 423677
24168 86231 338225
2763 391351 46707
4972 202813 102465
4488 ...

output:

1

result:

ok single line: '1'

Test #18:

score: 0
Accepted
time: 26ms
memory: 6384kb

input:

366753 49845 80666 977
205923 23224 70485
292244 47685 67796
217195 38820 70291
27387 21935 38966
352637 14805 42924
59337 3127 56783
293397 28614 54903
330283 26886 42058
319651 7541 43271
100022 25004 45893
327459 43954 20688
308516 23112 8279
338600 11828 31001
255036 8021 3407
275032 29861 61389...

output:

1

result:

ok single line: '1'

Test #19:

score: -100
Wrong Answer
time: 164ms
memory: 30404kb

input:

413 1 41 16884
0 0 0
0 0 1
0 0 2
0 0 3
0 0 4
0 0 5
0 0 6
0 0 7
0 0 8
0 0 9
0 0 10
0 0 11
0 0 12
0 0 13
0 0 14
0 0 15
0 0 16
0 0 17
0 0 18
0 0 19
0 0 20
0 0 21
0 0 22
0 0 23
0 0 24
0 0 25
0 0 26
0 0 27
0 0 28
0 0 29
0 0 30
0 0 31
0 0 32
0 0 33
0 0 34
0 0 35
0 0 36
0 0 37
0 0 38
0 0 39
0 0 40
1 0 0
1 ...

output:

1

result:

wrong answer 1st lines differ - expected: '49', found: '1'