# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
259231 |
2020-08-07T12:37:02 Z |
문홍윤(#5063) |
None (JOI12_constellation) |
C++17 |
|
72 ms |
7452 KB |
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pll;
const LL mod1=1e9+7;
pll operator-(pll a, pll b){return mp(a.F-b.F, a.S-b.S);}
LL ccw(pll a, pll b){return a.F*b.S-a.S*b.F;}
int n;
pair<pll, int> p[100010];
vector<int> uh, dh;
int arr[200010], re, sum1[200010], sum2[200010];
int qn, on, tn, h0, h1, h2;
LL ret;
int main(){
scanf("%d", &n);
for(int i=1; i<=n; i++){
scanf("%lld %lld %d", &p[i].F.F, &p[i].F.S, &p[i].S);
if(p[i].S==0)qn++;
if(p[i].S==1)on++;
if(p[i].S==2)tn++;
}
sort(p+1, p+n+1);
dh.eb(1); dh.eb(2);
for(int i=3; i<=n; i++){
while(dh.size()>1){
int p1=dh[dh.size()-2], p2=dh[dh.size()-1];
if(ccw(p[p2].F-p[p1].F, p[i].F-p[p2].F)>0)break;
dh.pop_back();
}
dh.eb(i);
}
uh.eb(n); uh.eb(n-1);
for(int i=n-2; i>=1; i--){
while(uh.size()>1){
int p1=uh[uh.size()-2], p2=uh[uh.size()-1];
if(ccw(p[p2].F-p[p1].F, p[i].F-p[p2].F)>0)break;
uh.pop_back();
}
uh.eb(i);
}
for(int i=0; i<dh.size()-1; i++)arr[re++]=p[dh[i]].S;
for(int i=0; i<uh.size()-1; i++)arr[re++]=p[uh[i]].S;
for(int i=0; i<re; i++){
if(arr[i]==0)h0++;
if(arr[i]==1)h1++;
if(arr[i]==2)h2++;
}
for(int i=0; i<dh.size()-1; i++)arr[re++]=p[dh[i]].S;
for(int i=0; i<uh.size()-1; i++)arr[re++]=p[uh[i]].S;
for(int i=0; i<re; i++){
if(i)sum1[i]=sum1[i-1], sum2[i]=sum2[i-1];
if(arr[i]==1)sum1[i]++;
if(arr[i]==2)sum2[i]++;
//printf("%d -%d\n", sum1[i], sum2[i]);
}
for(int i=0; i<re/2; i++){
int nw1=0, nw2=0;
if(i)nw1=sum1[i-1], nw2=sum2[i-1];
int f1=lower_bound(sum1, sum1+re, nw1+h1)-sum1;
int f2=lower_bound(sum2, sum2+re, nw2+1)-sum2;
//printf("! %d %d\n", f1, f2);
int tmp=min(i+re/2-1, f2)-max(i, f1);
if(tmp>0){ret+=tmp; ret%=mod1;}
}
//printf("!!%lld\n", ret);
if(!h1)ret++;
if(!h2)ret++;
for(int i=1; i<=qn-h0; i++){ret*=2ll; ret%=mod1;}
if(!on)ret--;
if(!tn)ret--;
printf("%lld", (ret+mod1)%mod1);
}
Compilation message
constellation.cpp: In function 'int main()':
constellation.cpp:49:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<dh.size()-1; i++)arr[re++]=p[dh[i]].S;
~^~~~~~~~~~~~
constellation.cpp:50:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<uh.size()-1; i++)arr[re++]=p[uh[i]].S;
~^~~~~~~~~~~~
constellation.cpp:56:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<dh.size()-1; i++)arr[re++]=p[dh[i]].S;
~^~~~~~~~~~~~
constellation.cpp:57:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<uh.size()-1; i++)arr[re++]=p[uh[i]].S;
~^~~~~~~~~~~~
constellation.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
constellation.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld %d", &p[i].F.F, &p[i].F.S, &p[i].S);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
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 |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
384 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
768 KB |
Output is correct |
3 |
Correct |
4 ms |
768 KB |
Output is correct |
4 |
Correct |
4 ms |
768 KB |
Output is correct |
5 |
Correct |
3 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
4 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
71 ms |
2944 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
60 ms |
4728 KB |
Output is correct |
5 |
Correct |
65 ms |
7412 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
768 KB |
Output is correct |
8 |
Correct |
4 ms |
768 KB |
Output is correct |
9 |
Correct |
5 ms |
768 KB |
Output is correct |
10 |
Correct |
69 ms |
7452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
57 ms |
2936 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
61 ms |
4836 KB |
Output is correct |
5 |
Correct |
72 ms |
7412 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
768 KB |
Output is correct |
8 |
Correct |
4 ms |
768 KB |
Output is correct |
9 |
Correct |
4 ms |
768 KB |
Output is correct |
10 |
Correct |
62 ms |
7412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
58 ms |
4728 KB |
Output is correct |
3 |
Correct |
61 ms |
7416 KB |
Output is correct |
4 |
Correct |
70 ms |
7412 KB |
Output is correct |
5 |
Correct |
71 ms |
5748 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
640 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
4 ms |
640 KB |
Output is correct |
10 |
Correct |
61 ms |
5364 KB |
Output is correct |
11 |
Correct |
60 ms |
5364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
57 ms |
2680 KB |
Output is correct |
3 |
Correct |
72 ms |
2680 KB |
Output is correct |
4 |
Correct |
64 ms |
5364 KB |
Output is correct |
5 |
Correct |
66 ms |
5428 KB |
Output is correct |
6 |
Correct |
67 ms |
5364 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
3 ms |
640 KB |
Output is correct |
10 |
Correct |
24 ms |
2804 KB |
Output is correct |