답안 #78679

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
78679 2018-10-07T05:15:53 Z nxteru Bulldozer (JOI17_bulldozer) C++14
80 / 100
1745 ms 87040 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cstdio>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
struct li{
  ll x,y;
  bool operator<(const li&q)const{
      if(y==0)return q.x*q.y>0;
      if(q.y==0)return x*y<0;
      return y*q.x<q.y*x;
  }
};
struct qu{
  ll x,y,k,a,b;
  bool operator<(const qu&q)const{
      if(y*q.x!=q.y*x){
          if(y==0)return q.x*q.y>0;
          if(q.y==0)return x*y<0;
          return y*q.x<q.y*x;
      }
      return k<q.k;
  }
};
struct po{
  ll x,y,i;
  bool operator<(const po&q)const{
      if(x!=q.x)return x>q.x;
      return y>q.y;
  }
};
struct sgt{
  ll x,ma,mi;  
};
ll n,k,x[2005],y[2005],w[2005],pl[2005],ans,seg[1<<12],sma[1<<12],smi[1<<12];
vector<P>line[2005];
map<li,ll>o;
vector<qu>q;
vector<po>poi;
bool vi[2005][2005];
void add(int a,ll c){
    a+=(1<<11)-1;
    sma[a]+=c;
    smi[a]+=c;
    while(a>0){
        a=(a-1)/2;
        sma[a]=max(sma[a*2+1],sma[a*2+2]);
        smi[a]=min(smi[a*2+1],smi[a*2+2]);
        seg[a]=max(max(seg[a*2+1],seg[a*2+2]),sma[a*2+2]-smi[a*2+1]);
    }
}
sgt que(int a,int b,int l,int r,int v){
    if(r<a||b<l)return sgt{0,-INF,INF};
    if(a<=l&&r<=b)return sgt{seg[v],sma[v],smi[v]};
    sgt ls=que(a,b,l,(l+r-1)/2,v*2+1),rs=que(a,b,(l+r+1)/2,r,v*2+2);
    return sgt{max(max(ls.x,rs.x),rs.ma-ls.mi),max(ls.ma,rs.ma),min(ls.mi,rs.mi)};
}
int main(void){
    scanf("%lld",&n);
    for(int i=0;i<n;i++)scanf("%lld%lld%lld",x+i,y+i,w+i);
    for(int i=0;i<n;i++){
        for(int j=0;j<k;j++)line[j].clear();
        k=0;
        o.clear();
        for(int j=i+1;j<n;j++){
            if(x[i]==x[j])continue;
            li p={x[i]-x[j],y[i]-y[j]};
            if(o.find(p)==o.end()){
                line[k].PB(P(-x[i],i));
                o[p]=k++;
            }
            line[o[p]].PB(P(-x[j],j));
        }
        for(int l=0;l<k;l++){
            sort(line[l].begin(),line[l].end());
            ll e=0;
            for(int a=0;a<line[l].size();a++){
                for(int b=a+1;b<line[l].size();b++){
                    int v=line[l][a].S,u=line[l][b].S;
                    if(vi[v][u]||vi[u][v])continue;
                    q.PB(qu{x[v]-x[u],y[v]-y[u],e,v,u});
                    e++;
                    vi[v][u]=true;
                    vi[u][v]=true;
                }
            }
        }
    }
    for(int i=0;i<n;i++)poi.PB(po{x[i],y[i],i});
    sort(poi.begin(),poi.end());
    ll s=0;
    for(int i=0;i<n;i++){
        s+=w[poi[i].i];
        pl[poi[i].i]=i+1;
        add(i+1,s);
    }
    ans=max(ans,que(0,n,0,(1<<11)-1,0).x);
    sort(q.begin(),q.end());
    for(int i=0;i<q.size();i++){
        vector<P>t;
        t.PB(P(q[i].a,q[i].b));
        while(i+1<q.size()&&q[i].y*q[i+1].x==q[i+1].y*q[i].x){
            i++;
            t.PB(P(q[i].a,q[i].b));
        }
        for(int j=0;j<t.size();j++){
            ll a=pl[t[j].F],b=pl[t[j].S],wa=w[t[j].F],wb=w[t[j].S];
            pl[t[j].F]=b;
            pl[t[j].S]=a;
            if(a>b){
                swap(a,b);
                swap(wa,wb);
            }
            add(a,-wa+wb);
        }
        ans=max(ans,que(0,n,0,(1<<11)-1,0).x);
    }
    printf("%lld\n",ans);
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:84:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int a=0;a<line[l].size();a++){
                         ~^~~~~~~~~~~~~~~
bulldozer.cpp:85:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(int b=a+1;b<line[l].size();b++){
                               ~^~~~~~~~~~~~~~~
bulldozer.cpp:106:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<q.size();i++){
                 ~^~~~~~~~~
bulldozer.cpp:109:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(i+1<q.size()&&q[i].y*q[i+1].x==q[i+1].y*q[i].x){
               ~~~^~~~~~~~~
bulldozer.cpp:113:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<t.size();j++){
                     ~^~~~~~~~~
bulldozer.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&n);
     ~~~~~^~~~~~~~~~~
bulldozer.cpp:67:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=0;i<n;i++)scanf("%lld%lld%lld",x+i,y+i,w+i);
                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1084 KB Output is correct
2 Correct 4 ms 1084 KB Output is correct
3 Correct 4 ms 1084 KB Output is correct
4 Correct 3 ms 1060 KB Output is correct
5 Correct 3 ms 1084 KB Output is correct
6 Correct 3 ms 1084 KB Output is correct
7 Correct 3 ms 1084 KB Output is correct
8 Correct 4 ms 1120 KB Output is correct
9 Correct 4 ms 1084 KB Output is correct
10 Correct 4 ms 1120 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1120 KB Output is correct
2 Correct 5 ms 1120 KB Output is correct
3 Correct 5 ms 1120 KB Output is correct
4 Correct 6 ms 1120 KB Output is correct
5 Correct 5 ms 1120 KB Output is correct
6 Correct 5 ms 992 KB Output is correct
7 Correct 6 ms 1120 KB Output is correct
8 Correct 5 ms 992 KB Output is correct
9 Correct 5 ms 1120 KB Output is correct
10 Correct 5 ms 1120 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 6 ms 1120 KB Output is correct
22 Correct 5 ms 1120 KB Output is correct
23 Correct 5 ms 1120 KB Output is correct
24 Correct 5 ms 1120 KB Output is correct
25 Correct 5 ms 1120 KB Output is correct
26 Correct 5 ms 1092 KB Output is correct
27 Correct 5 ms 992 KB Output is correct
28 Correct 5 ms 992 KB Output is correct
29 Correct 5 ms 1120 KB Output is correct
30 Correct 5 ms 1120 KB Output is correct
31 Correct 5 ms 1120 KB Output is correct
32 Correct 6 ms 1120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1120 KB Output is correct
2 Correct 5 ms 1120 KB Output is correct
3 Correct 5 ms 1120 KB Output is correct
4 Correct 6 ms 1120 KB Output is correct
5 Correct 5 ms 1120 KB Output is correct
6 Correct 5 ms 992 KB Output is correct
7 Correct 6 ms 1120 KB Output is correct
8 Correct 5 ms 992 KB Output is correct
9 Correct 5 ms 1120 KB Output is correct
10 Correct 5 ms 1120 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 6 ms 1120 KB Output is correct
22 Correct 5 ms 1120 KB Output is correct
23 Correct 5 ms 1120 KB Output is correct
24 Correct 5 ms 1120 KB Output is correct
25 Correct 5 ms 1120 KB Output is correct
26 Correct 5 ms 1092 KB Output is correct
27 Correct 5 ms 992 KB Output is correct
28 Correct 5 ms 992 KB Output is correct
29 Correct 5 ms 1120 KB Output is correct
30 Correct 5 ms 1120 KB Output is correct
31 Correct 5 ms 1120 KB Output is correct
32 Correct 6 ms 1120 KB Output is correct
33 Correct 1641 ms 86780 KB Output is correct
34 Correct 1679 ms 86816 KB Output is correct
35 Correct 1585 ms 86844 KB Output is correct
36 Correct 1590 ms 86940 KB Output is correct
37 Correct 1609 ms 86832 KB Output is correct
38 Correct 1594 ms 86856 KB Output is correct
39 Correct 1600 ms 86908 KB Output is correct
40 Correct 1605 ms 86724 KB Output is correct
41 Correct 1605 ms 86828 KB Output is correct
42 Correct 1643 ms 86816 KB Output is correct
43 Correct 1609 ms 86860 KB Output is correct
44 Correct 1592 ms 86800 KB Output is correct
45 Correct 1603 ms 86796 KB Output is correct
46 Correct 1601 ms 86908 KB Output is correct
47 Correct 1617 ms 86796 KB Output is correct
48 Correct 1600 ms 86816 KB Output is correct
49 Correct 1595 ms 86792 KB Output is correct
50 Correct 1745 ms 86824 KB Output is correct
51 Correct 1656 ms 86920 KB Output is correct
52 Correct 1666 ms 86724 KB Output is correct
53 Correct 1586 ms 86840 KB Output is correct
54 Correct 1581 ms 86920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1120 KB Output is correct
2 Correct 5 ms 1120 KB Output is correct
3 Correct 5 ms 1120 KB Output is correct
4 Correct 6 ms 1120 KB Output is correct
5 Correct 5 ms 1120 KB Output is correct
6 Correct 5 ms 992 KB Output is correct
7 Correct 6 ms 1120 KB Output is correct
8 Correct 5 ms 992 KB Output is correct
9 Correct 5 ms 1120 KB Output is correct
10 Correct 5 ms 1120 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 6 ms 1120 KB Output is correct
22 Correct 5 ms 1120 KB Output is correct
23 Correct 5 ms 1120 KB Output is correct
24 Correct 5 ms 1120 KB Output is correct
25 Correct 5 ms 1120 KB Output is correct
26 Correct 5 ms 1092 KB Output is correct
27 Correct 5 ms 992 KB Output is correct
28 Correct 5 ms 992 KB Output is correct
29 Correct 5 ms 1120 KB Output is correct
30 Correct 5 ms 1120 KB Output is correct
31 Correct 5 ms 1120 KB Output is correct
32 Correct 6 ms 1120 KB Output is correct
33 Correct 1641 ms 86780 KB Output is correct
34 Correct 1679 ms 86816 KB Output is correct
35 Correct 1585 ms 86844 KB Output is correct
36 Correct 1590 ms 86940 KB Output is correct
37 Correct 1609 ms 86832 KB Output is correct
38 Correct 1594 ms 86856 KB Output is correct
39 Correct 1600 ms 86908 KB Output is correct
40 Correct 1605 ms 86724 KB Output is correct
41 Correct 1605 ms 86828 KB Output is correct
42 Correct 1643 ms 86816 KB Output is correct
43 Correct 1609 ms 86860 KB Output is correct
44 Correct 1592 ms 86800 KB Output is correct
45 Correct 1603 ms 86796 KB Output is correct
46 Correct 1601 ms 86908 KB Output is correct
47 Correct 1617 ms 86796 KB Output is correct
48 Correct 1600 ms 86816 KB Output is correct
49 Correct 1595 ms 86792 KB Output is correct
50 Correct 1745 ms 86824 KB Output is correct
51 Correct 1656 ms 86920 KB Output is correct
52 Correct 1666 ms 86724 KB Output is correct
53 Correct 1586 ms 86840 KB Output is correct
54 Correct 1581 ms 86920 KB Output is correct
55 Correct 1627 ms 86788 KB Output is correct
56 Correct 1595 ms 86840 KB Output is correct
57 Correct 1580 ms 86716 KB Output is correct
58 Correct 1594 ms 86792 KB Output is correct
59 Correct 1597 ms 86924 KB Output is correct
60 Correct 1627 ms 86888 KB Output is correct
61 Correct 1626 ms 86788 KB Output is correct
62 Correct 1605 ms 86736 KB Output is correct
63 Correct 1604 ms 86856 KB Output is correct
64 Correct 1669 ms 86848 KB Output is correct
65 Correct 1625 ms 86748 KB Output is correct
66 Correct 1590 ms 86792 KB Output is correct
67 Correct 1622 ms 86760 KB Output is correct
68 Correct 1662 ms 86768 KB Output is correct
69 Correct 1604 ms 86788 KB Output is correct
70 Correct 1678 ms 86792 KB Output is correct
71 Correct 1624 ms 86792 KB Output is correct
72 Correct 1647 ms 86916 KB Output is correct
73 Correct 1613 ms 86768 KB Output is correct
74 Correct 1586 ms 86772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1084 KB Output is correct
2 Correct 4 ms 1084 KB Output is correct
3 Correct 4 ms 1084 KB Output is correct
4 Correct 3 ms 1060 KB Output is correct
5 Correct 3 ms 1084 KB Output is correct
6 Correct 3 ms 1084 KB Output is correct
7 Correct 3 ms 1084 KB Output is correct
8 Correct 4 ms 1120 KB Output is correct
9 Correct 4 ms 1084 KB Output is correct
10 Correct 4 ms 1120 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 5 ms 1120 KB Output is correct
17 Correct 5 ms 1120 KB Output is correct
18 Correct 5 ms 1120 KB Output is correct
19 Correct 6 ms 1120 KB Output is correct
20 Correct 5 ms 1120 KB Output is correct
21 Correct 5 ms 992 KB Output is correct
22 Correct 6 ms 1120 KB Output is correct
23 Correct 5 ms 992 KB Output is correct
24 Correct 5 ms 1120 KB Output is correct
25 Correct 5 ms 1120 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 6 ms 1120 KB Output is correct
37 Correct 5 ms 1120 KB Output is correct
38 Correct 5 ms 1120 KB Output is correct
39 Correct 5 ms 1120 KB Output is correct
40 Correct 5 ms 1120 KB Output is correct
41 Correct 5 ms 1092 KB Output is correct
42 Correct 5 ms 992 KB Output is correct
43 Correct 5 ms 992 KB Output is correct
44 Correct 5 ms 1120 KB Output is correct
45 Correct 5 ms 1120 KB Output is correct
46 Correct 5 ms 1120 KB Output is correct
47 Correct 6 ms 1120 KB Output is correct
48 Correct 1641 ms 86780 KB Output is correct
49 Correct 1679 ms 86816 KB Output is correct
50 Correct 1585 ms 86844 KB Output is correct
51 Correct 1590 ms 86940 KB Output is correct
52 Correct 1609 ms 86832 KB Output is correct
53 Correct 1594 ms 86856 KB Output is correct
54 Correct 1600 ms 86908 KB Output is correct
55 Correct 1605 ms 86724 KB Output is correct
56 Correct 1605 ms 86828 KB Output is correct
57 Correct 1643 ms 86816 KB Output is correct
58 Correct 1609 ms 86860 KB Output is correct
59 Correct 1592 ms 86800 KB Output is correct
60 Correct 1603 ms 86796 KB Output is correct
61 Correct 1601 ms 86908 KB Output is correct
62 Correct 1617 ms 86796 KB Output is correct
63 Correct 1600 ms 86816 KB Output is correct
64 Correct 1595 ms 86792 KB Output is correct
65 Correct 1745 ms 86824 KB Output is correct
66 Correct 1656 ms 86920 KB Output is correct
67 Correct 1666 ms 86724 KB Output is correct
68 Correct 1586 ms 86840 KB Output is correct
69 Correct 1581 ms 86920 KB Output is correct
70 Correct 1627 ms 86788 KB Output is correct
71 Correct 1595 ms 86840 KB Output is correct
72 Correct 1580 ms 86716 KB Output is correct
73 Correct 1594 ms 86792 KB Output is correct
74 Correct 1597 ms 86924 KB Output is correct
75 Correct 1627 ms 86888 KB Output is correct
76 Correct 1626 ms 86788 KB Output is correct
77 Correct 1605 ms 86736 KB Output is correct
78 Correct 1604 ms 86856 KB Output is correct
79 Correct 1669 ms 86848 KB Output is correct
80 Correct 1625 ms 86748 KB Output is correct
81 Correct 1590 ms 86792 KB Output is correct
82 Correct 1622 ms 86760 KB Output is correct
83 Correct 1662 ms 86768 KB Output is correct
84 Correct 1604 ms 86788 KB Output is correct
85 Correct 1678 ms 86792 KB Output is correct
86 Correct 1624 ms 86792 KB Output is correct
87 Correct 1647 ms 86916 KB Output is correct
88 Correct 1613 ms 86768 KB Output is correct
89 Correct 1586 ms 86772 KB Output is correct
90 Correct 1615 ms 86756 KB Output is correct
91 Correct 1621 ms 87036 KB Output is correct
92 Correct 1632 ms 86820 KB Output is correct
93 Correct 1622 ms 86988 KB Output is correct
94 Correct 1655 ms 86844 KB Output is correct
95 Correct 1645 ms 86720 KB Output is correct
96 Correct 1639 ms 87040 KB Output is correct
97 Correct 1606 ms 86808 KB Output is correct
98 Correct 1601 ms 86724 KB Output is correct
99 Correct 1580 ms 86864 KB Output is correct
100 Correct 782 ms 45620 KB Output is correct
101 Correct 800 ms 45620 KB Output is correct
102 Correct 768 ms 45748 KB Output is correct
103 Correct 760 ms 45620 KB Output is correct
104 Correct 766 ms 45620 KB Output is correct
105 Correct 1071 ms 86664 KB Output is correct
106 Correct 1060 ms 86748 KB Output is correct
107 Correct 1073 ms 86784 KB Output is correct
108 Correct 1117 ms 86664 KB Output is correct
109 Correct 1081 ms 86716 KB Output is correct
110 Correct 1214 ms 86920 KB Output is correct
111 Correct 1161 ms 86848 KB Output is correct
112 Correct 1160 ms 86772 KB Output is correct
113 Correct 1161 ms 86792 KB Output is correct
114 Correct 1161 ms 86920 KB Output is correct
115 Correct 1157 ms 86852 KB Output is correct
116 Correct 1166 ms 86772 KB Output is correct
117 Correct 1188 ms 86820 KB Output is correct
118 Correct 1147 ms 86916 KB Output is correct
119 Correct 1163 ms 86760 KB Output is correct
120 Correct 2 ms 384 KB Output is correct
121 Correct 2 ms 512 KB Output is correct
122 Incorrect 1558 ms 86772 KB Output isn't correct
123 Halted 0 ms 0 KB -