# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
301913 | 2020-09-18T09:41:18 Z | milisav | Monochrome Points (JOI20_monochrome) | C++14 | 767 ms | 5640 KB |
#include<bits/stdc++.h> #pragma GCC optimize("O3") #define maxn 1000000 using namespace std; int n; long long ans=0; char s[2*maxn]; int d[2*maxn]; int bit[8*maxn]; void update(int p,int v) { while(p<=2*n) { bit[p]+=v; p+=(p&(-p)); } } int query(int p) { int ret=0; while(p>0) { ret+=bit[p]; p-=(p&(-p)); } return ret; } int l[maxn]; int r[maxn]; long long val(int i) { int cb=0; int x=0; int y=0; long long cans=0; int tmp=0; while(cb<i || s[y]!='B') { if(s[y]=='B') cb++; y++; if(y==2*n) y=0; } int k=1; l[k]=x; r[k]=y; d[x]=-k; d[y]=k; x++; while(x<2*n) { if(s[x]=='W') { k++; do { y++; if(y==2*n) y=0; } while(s[y]!='B'); l[k]=min(x,y); r[k]=max(x,y); d[min(x,y)]=-k; d[max(x,y)]=k; } x++; } for(int i=0;i<2*n;i++) { if(d[i]>0) { update(l[d[i]]+1,-1); cans+=query(r[d[i]]+1)-query(l[d[i]]+1); } else update(i+1,1); } return cans; } int main() { scanf("%d",&n); scanf("%s",s); if(s[0]=='B') { for(int i=0;i<2*n;i++) { if(s[i]=='B') s[i]='W'; else s[i]='B'; } } int l=0,r=n-1; while(l<r) { int m1=(l+r)>>1; int m2=m1+1; long long v1=val(m1); long long v2=val(m2); ans=max(ans,v1); ans=max(ans,v2); if(v1>v2) r=m2-1; else l=m1+1; } ans=max(ans,val(l)); printf("%lld",ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 512 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 0 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 1 ms | 360 KB | Output is correct |
12 | Correct | 1 ms | 384 KB | Output is correct |
13 | Correct | 1 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 512 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 0 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 1 ms | 360 KB | Output is correct |
12 | Correct | 1 ms | 384 KB | Output is correct |
13 | Correct | 1 ms | 384 KB | Output is correct |
14 | Correct | 1 ms | 384 KB | Output is correct |
15 | Correct | 1 ms | 384 KB | Output is correct |
16 | Correct | 1 ms | 384 KB | Output is correct |
17 | Correct | 1 ms | 384 KB | Output is correct |
18 | Correct | 1 ms | 384 KB | Output is correct |
19 | Correct | 1 ms | 384 KB | Output is correct |
20 | Correct | 1 ms | 384 KB | Output is correct |
21 | Correct | 1 ms | 384 KB | Output is correct |
22 | Correct | 1 ms | 384 KB | Output is correct |
23 | Correct | 1 ms | 384 KB | Output is correct |
24 | Correct | 1 ms | 384 KB | Output is correct |
25 | Correct | 1 ms | 384 KB | Output is correct |
26 | Correct | 1 ms | 512 KB | Output is correct |
27 | Correct | 1 ms | 360 KB | Output is correct |
28 | Correct | 1 ms | 384 KB | Output is correct |
29 | Correct | 1 ms | 384 KB | Output is correct |
30 | Correct | 1 ms | 384 KB | Output is correct |
31 | Correct | 1 ms | 416 KB | Output is correct |
32 | Correct | 1 ms | 384 KB | Output is correct |
33 | Correct | 1 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 512 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 0 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 1 ms | 360 KB | Output is correct |
12 | Correct | 1 ms | 384 KB | Output is correct |
13 | Correct | 1 ms | 384 KB | Output is correct |
14 | Correct | 1 ms | 384 KB | Output is correct |
15 | Correct | 1 ms | 384 KB | Output is correct |
16 | Correct | 1 ms | 384 KB | Output is correct |
17 | Correct | 1 ms | 384 KB | Output is correct |
18 | Correct | 1 ms | 384 KB | Output is correct |
19 | Correct | 1 ms | 384 KB | Output is correct |
20 | Correct | 1 ms | 384 KB | Output is correct |
21 | Correct | 1 ms | 384 KB | Output is correct |
22 | Correct | 1 ms | 384 KB | Output is correct |
23 | Correct | 1 ms | 384 KB | Output is correct |
24 | Correct | 1 ms | 384 KB | Output is correct |
25 | Correct | 1 ms | 384 KB | Output is correct |
26 | Correct | 1 ms | 512 KB | Output is correct |
27 | Correct | 1 ms | 360 KB | Output is correct |
28 | Correct | 1 ms | 384 KB | Output is correct |
29 | Correct | 1 ms | 384 KB | Output is correct |
30 | Correct | 1 ms | 384 KB | Output is correct |
31 | Correct | 1 ms | 416 KB | Output is correct |
32 | Correct | 1 ms | 384 KB | Output is correct |
33 | Correct | 1 ms | 384 KB | Output is correct |
34 | Correct | 4 ms | 384 KB | Output is correct |
35 | Correct | 4 ms | 384 KB | Output is correct |
36 | Correct | 4 ms | 384 KB | Output is correct |
37 | Correct | 4 ms | 384 KB | Output is correct |
38 | Correct | 3 ms | 384 KB | Output is correct |
39 | Correct | 3 ms | 384 KB | Output is correct |
40 | Correct | 4 ms | 384 KB | Output is correct |
41 | Correct | 4 ms | 384 KB | Output is correct |
42 | Correct | 4 ms | 384 KB | Output is correct |
43 | Correct | 3 ms | 416 KB | Output is correct |
44 | Correct | 4 ms | 384 KB | Output is correct |
45 | Correct | 3 ms | 384 KB | Output is correct |
46 | Correct | 3 ms | 384 KB | Output is correct |
47 | Correct | 3 ms | 384 KB | Output is correct |
48 | Correct | 3 ms | 384 KB | Output is correct |
49 | Correct | 3 ms | 384 KB | Output is correct |
50 | Correct | 3 ms | 384 KB | Output is correct |
51 | Correct | 3 ms | 384 KB | Output is correct |
52 | Correct | 3 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 512 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 0 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 1 ms | 360 KB | Output is correct |
12 | Correct | 1 ms | 384 KB | Output is correct |
13 | Correct | 1 ms | 384 KB | Output is correct |
14 | Correct | 1 ms | 384 KB | Output is correct |
15 | Correct | 1 ms | 384 KB | Output is correct |
16 | Correct | 1 ms | 384 KB | Output is correct |
17 | Correct | 1 ms | 384 KB | Output is correct |
18 | Correct | 1 ms | 384 KB | Output is correct |
19 | Correct | 1 ms | 384 KB | Output is correct |
20 | Correct | 1 ms | 384 KB | Output is correct |
21 | Correct | 1 ms | 384 KB | Output is correct |
22 | Correct | 1 ms | 384 KB | Output is correct |
23 | Correct | 1 ms | 384 KB | Output is correct |
24 | Correct | 1 ms | 384 KB | Output is correct |
25 | Correct | 1 ms | 384 KB | Output is correct |
26 | Correct | 1 ms | 512 KB | Output is correct |
27 | Correct | 1 ms | 360 KB | Output is correct |
28 | Correct | 1 ms | 384 KB | Output is correct |
29 | Correct | 1 ms | 384 KB | Output is correct |
30 | Correct | 1 ms | 384 KB | Output is correct |
31 | Correct | 1 ms | 416 KB | Output is correct |
32 | Correct | 1 ms | 384 KB | Output is correct |
33 | Correct | 1 ms | 384 KB | Output is correct |
34 | Correct | 4 ms | 384 KB | Output is correct |
35 | Correct | 4 ms | 384 KB | Output is correct |
36 | Correct | 4 ms | 384 KB | Output is correct |
37 | Correct | 4 ms | 384 KB | Output is correct |
38 | Correct | 3 ms | 384 KB | Output is correct |
39 | Correct | 3 ms | 384 KB | Output is correct |
40 | Correct | 4 ms | 384 KB | Output is correct |
41 | Correct | 4 ms | 384 KB | Output is correct |
42 | Correct | 4 ms | 384 KB | Output is correct |
43 | Correct | 3 ms | 416 KB | Output is correct |
44 | Correct | 4 ms | 384 KB | Output is correct |
45 | Correct | 3 ms | 384 KB | Output is correct |
46 | Correct | 3 ms | 384 KB | Output is correct |
47 | Correct | 3 ms | 384 KB | Output is correct |
48 | Correct | 3 ms | 384 KB | Output is correct |
49 | Correct | 3 ms | 384 KB | Output is correct |
50 | Correct | 3 ms | 384 KB | Output is correct |
51 | Correct | 3 ms | 384 KB | Output is correct |
52 | Correct | 3 ms | 384 KB | Output is correct |
53 | Correct | 760 ms | 5240 KB | Output is correct |
54 | Correct | 760 ms | 5640 KB | Output is correct |
55 | Correct | 714 ms | 5240 KB | Output is correct |
56 | Correct | 767 ms | 5240 KB | Output is correct |
57 | Correct | 587 ms | 5112 KB | Output is correct |
58 | Correct | 587 ms | 5240 KB | Output is correct |
59 | Correct | 544 ms | 5112 KB | Output is correct |
60 | Correct | 592 ms | 5292 KB | Output is correct |
61 | Correct | 593 ms | 5368 KB | Output is correct |
62 | Correct | 614 ms | 5364 KB | Output is correct |
63 | Correct | 631 ms | 5372 KB | Output is correct |
64 | Correct | 592 ms | 5240 KB | Output is correct |
65 | Correct | 571 ms | 5112 KB | Output is correct |
66 | Correct | 562 ms | 5240 KB | Output is correct |
67 | Correct | 562 ms | 5368 KB | Output is correct |
68 | Correct | 567 ms | 5112 KB | Output is correct |
69 | Correct | 564 ms | 5368 KB | Output is correct |
70 | Correct | 549 ms | 5112 KB | Output is correct |
71 | Correct | 598 ms | 5240 KB | Output is correct |
72 | Correct | 594 ms | 5120 KB | Output is correct |
73 | Correct | 638 ms | 5624 KB | Output is correct |