답안 #78680

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
78680 2018-10-07T05:21:07 Z nxteru Bulldozer (JOI17_bulldozer) C++14
80 / 100
1417 ms 86976 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;
  }
};
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]);
    }
}
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);
    }
    for(int i=n+1;i<(1<<11);i++)add(i,-INF);
    ans=max(ans,seg[0]);
    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,seg[0]);
    }
    printf("%lld\n",ans);
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:75:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int a=0;a<line[l].size();a++){
                         ~^~~~~~~~~~~~~~~
bulldozer.cpp:76:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(int b=a+1;b<line[l].size();b++){
                               ~^~~~~~~~~~~~~~~
bulldozer.cpp:98:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<q.size();i++){
                 ~^~~~~~~~~
bulldozer.cpp:101: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:105:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<t.size();j++){
                     ~^~~~~~~~~
bulldozer.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&n);
     ~~~~~^~~~~~~~~~~
bulldozer.cpp:58: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 5 ms 1084 KB Output is correct
3 Correct 4 ms 1084 KB Output is correct
4 Correct 4 ms 1084 KB Output is correct
5 Correct 4 ms 1084 KB Output is correct
6 Correct 4 ms 1168 KB Output is correct
7 Correct 4 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 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 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 4 ms 1120 KB Output is correct
3 Correct 5 ms 1120 KB Output is correct
4 Correct 4 ms 1120 KB Output is correct
5 Correct 4 ms 1120 KB Output is correct
6 Correct 4 ms 1120 KB Output is correct
7 Correct 4 ms 1120 KB Output is correct
8 Correct 5 ms 1120 KB Output is correct
9 Correct 4 ms 992 KB Output is correct
10 Correct 4 ms 992 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 3 ms 556 KB Output is correct
21 Correct 4 ms 1120 KB Output is correct
22 Correct 5 ms 1012 KB Output is correct
23 Correct 4 ms 1040 KB Output is correct
24 Correct 5 ms 992 KB Output is correct
25 Correct 5 ms 1120 KB Output is correct
26 Correct 4 ms 992 KB Output is correct
27 Correct 4 ms 1120 KB Output is correct
28 Correct 5 ms 992 KB Output is correct
29 Correct 5 ms 1120 KB Output is correct
30 Correct 4 ms 992 KB Output is correct
31 Correct 5 ms 1120 KB Output is correct
32 Correct 4 ms 1120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1120 KB Output is correct
2 Correct 4 ms 1120 KB Output is correct
3 Correct 5 ms 1120 KB Output is correct
4 Correct 4 ms 1120 KB Output is correct
5 Correct 4 ms 1120 KB Output is correct
6 Correct 4 ms 1120 KB Output is correct
7 Correct 4 ms 1120 KB Output is correct
8 Correct 5 ms 1120 KB Output is correct
9 Correct 4 ms 992 KB Output is correct
10 Correct 4 ms 992 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 3 ms 556 KB Output is correct
21 Correct 4 ms 1120 KB Output is correct
22 Correct 5 ms 1012 KB Output is correct
23 Correct 4 ms 1040 KB Output is correct
24 Correct 5 ms 992 KB Output is correct
25 Correct 5 ms 1120 KB Output is correct
26 Correct 4 ms 992 KB Output is correct
27 Correct 4 ms 1120 KB Output is correct
28 Correct 5 ms 992 KB Output is correct
29 Correct 5 ms 1120 KB Output is correct
30 Correct 4 ms 992 KB Output is correct
31 Correct 5 ms 1120 KB Output is correct
32 Correct 4 ms 1120 KB Output is correct
33 Correct 1400 ms 86920 KB Output is correct
34 Correct 1334 ms 86920 KB Output is correct
35 Correct 1347 ms 86892 KB Output is correct
36 Correct 1368 ms 86768 KB Output is correct
37 Correct 1312 ms 86792 KB Output is correct
38 Correct 1322 ms 86820 KB Output is correct
39 Correct 1338 ms 86804 KB Output is correct
40 Correct 1356 ms 86920 KB Output is correct
41 Correct 1327 ms 86804 KB Output is correct
42 Correct 1348 ms 86752 KB Output is correct
43 Correct 1308 ms 86780 KB Output is correct
44 Correct 1310 ms 86824 KB Output is correct
45 Correct 1329 ms 86764 KB Output is correct
46 Correct 1303 ms 86760 KB Output is correct
47 Correct 1312 ms 86792 KB Output is correct
48 Correct 1303 ms 86884 KB Output is correct
49 Correct 1289 ms 86816 KB Output is correct
50 Correct 1328 ms 86740 KB Output is correct
51 Correct 1309 ms 86748 KB Output is correct
52 Correct 1317 ms 86828 KB Output is correct
53 Correct 1317 ms 86944 KB Output is correct
54 Correct 1330 ms 86768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1120 KB Output is correct
2 Correct 4 ms 1120 KB Output is correct
3 Correct 5 ms 1120 KB Output is correct
4 Correct 4 ms 1120 KB Output is correct
5 Correct 4 ms 1120 KB Output is correct
6 Correct 4 ms 1120 KB Output is correct
7 Correct 4 ms 1120 KB Output is correct
8 Correct 5 ms 1120 KB Output is correct
9 Correct 4 ms 992 KB Output is correct
10 Correct 4 ms 992 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 3 ms 556 KB Output is correct
21 Correct 4 ms 1120 KB Output is correct
22 Correct 5 ms 1012 KB Output is correct
23 Correct 4 ms 1040 KB Output is correct
24 Correct 5 ms 992 KB Output is correct
25 Correct 5 ms 1120 KB Output is correct
26 Correct 4 ms 992 KB Output is correct
27 Correct 4 ms 1120 KB Output is correct
28 Correct 5 ms 992 KB Output is correct
29 Correct 5 ms 1120 KB Output is correct
30 Correct 4 ms 992 KB Output is correct
31 Correct 5 ms 1120 KB Output is correct
32 Correct 4 ms 1120 KB Output is correct
33 Correct 1400 ms 86920 KB Output is correct
34 Correct 1334 ms 86920 KB Output is correct
35 Correct 1347 ms 86892 KB Output is correct
36 Correct 1368 ms 86768 KB Output is correct
37 Correct 1312 ms 86792 KB Output is correct
38 Correct 1322 ms 86820 KB Output is correct
39 Correct 1338 ms 86804 KB Output is correct
40 Correct 1356 ms 86920 KB Output is correct
41 Correct 1327 ms 86804 KB Output is correct
42 Correct 1348 ms 86752 KB Output is correct
43 Correct 1308 ms 86780 KB Output is correct
44 Correct 1310 ms 86824 KB Output is correct
45 Correct 1329 ms 86764 KB Output is correct
46 Correct 1303 ms 86760 KB Output is correct
47 Correct 1312 ms 86792 KB Output is correct
48 Correct 1303 ms 86884 KB Output is correct
49 Correct 1289 ms 86816 KB Output is correct
50 Correct 1328 ms 86740 KB Output is correct
51 Correct 1309 ms 86748 KB Output is correct
52 Correct 1317 ms 86828 KB Output is correct
53 Correct 1317 ms 86944 KB Output is correct
54 Correct 1330 ms 86768 KB Output is correct
55 Correct 1345 ms 86736 KB Output is correct
56 Correct 1368 ms 86744 KB Output is correct
57 Correct 1400 ms 86920 KB Output is correct
58 Correct 1385 ms 86920 KB Output is correct
59 Correct 1404 ms 86864 KB Output is correct
60 Correct 1301 ms 86792 KB Output is correct
61 Correct 1335 ms 86780 KB Output is correct
62 Correct 1326 ms 86732 KB Output is correct
63 Correct 1331 ms 86772 KB Output is correct
64 Correct 1351 ms 86876 KB Output is correct
65 Correct 1332 ms 86832 KB Output is correct
66 Correct 1344 ms 86900 KB Output is correct
67 Correct 1342 ms 86880 KB Output is correct
68 Correct 1300 ms 86856 KB Output is correct
69 Correct 1318 ms 86840 KB Output is correct
70 Correct 1308 ms 86900 KB Output is correct
71 Correct 1323 ms 86792 KB Output is correct
72 Correct 1348 ms 86792 KB Output is correct
73 Correct 1321 ms 86832 KB Output is correct
74 Correct 1360 ms 86764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1084 KB Output is correct
2 Correct 5 ms 1084 KB Output is correct
3 Correct 4 ms 1084 KB Output is correct
4 Correct 4 ms 1084 KB Output is correct
5 Correct 4 ms 1084 KB Output is correct
6 Correct 4 ms 1168 KB Output is correct
7 Correct 4 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 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 5 ms 1120 KB Output is correct
17 Correct 4 ms 1120 KB Output is correct
18 Correct 5 ms 1120 KB Output is correct
19 Correct 4 ms 1120 KB Output is correct
20 Correct 4 ms 1120 KB Output is correct
21 Correct 4 ms 1120 KB Output is correct
22 Correct 4 ms 1120 KB Output is correct
23 Correct 5 ms 1120 KB Output is correct
24 Correct 4 ms 992 KB Output is correct
25 Correct 4 ms 992 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 2 ms 512 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 2 ms 512 KB Output is correct
34 Correct 2 ms 512 KB Output is correct
35 Correct 3 ms 556 KB Output is correct
36 Correct 4 ms 1120 KB Output is correct
37 Correct 5 ms 1012 KB Output is correct
38 Correct 4 ms 1040 KB Output is correct
39 Correct 5 ms 992 KB Output is correct
40 Correct 5 ms 1120 KB Output is correct
41 Correct 4 ms 992 KB Output is correct
42 Correct 4 ms 1120 KB Output is correct
43 Correct 5 ms 992 KB Output is correct
44 Correct 5 ms 1120 KB Output is correct
45 Correct 4 ms 992 KB Output is correct
46 Correct 5 ms 1120 KB Output is correct
47 Correct 4 ms 1120 KB Output is correct
48 Correct 1400 ms 86920 KB Output is correct
49 Correct 1334 ms 86920 KB Output is correct
50 Correct 1347 ms 86892 KB Output is correct
51 Correct 1368 ms 86768 KB Output is correct
52 Correct 1312 ms 86792 KB Output is correct
53 Correct 1322 ms 86820 KB Output is correct
54 Correct 1338 ms 86804 KB Output is correct
55 Correct 1356 ms 86920 KB Output is correct
56 Correct 1327 ms 86804 KB Output is correct
57 Correct 1348 ms 86752 KB Output is correct
58 Correct 1308 ms 86780 KB Output is correct
59 Correct 1310 ms 86824 KB Output is correct
60 Correct 1329 ms 86764 KB Output is correct
61 Correct 1303 ms 86760 KB Output is correct
62 Correct 1312 ms 86792 KB Output is correct
63 Correct 1303 ms 86884 KB Output is correct
64 Correct 1289 ms 86816 KB Output is correct
65 Correct 1328 ms 86740 KB Output is correct
66 Correct 1309 ms 86748 KB Output is correct
67 Correct 1317 ms 86828 KB Output is correct
68 Correct 1317 ms 86944 KB Output is correct
69 Correct 1330 ms 86768 KB Output is correct
70 Correct 1345 ms 86736 KB Output is correct
71 Correct 1368 ms 86744 KB Output is correct
72 Correct 1400 ms 86920 KB Output is correct
73 Correct 1385 ms 86920 KB Output is correct
74 Correct 1404 ms 86864 KB Output is correct
75 Correct 1301 ms 86792 KB Output is correct
76 Correct 1335 ms 86780 KB Output is correct
77 Correct 1326 ms 86732 KB Output is correct
78 Correct 1331 ms 86772 KB Output is correct
79 Correct 1351 ms 86876 KB Output is correct
80 Correct 1332 ms 86832 KB Output is correct
81 Correct 1344 ms 86900 KB Output is correct
82 Correct 1342 ms 86880 KB Output is correct
83 Correct 1300 ms 86856 KB Output is correct
84 Correct 1318 ms 86840 KB Output is correct
85 Correct 1308 ms 86900 KB Output is correct
86 Correct 1323 ms 86792 KB Output is correct
87 Correct 1348 ms 86792 KB Output is correct
88 Correct 1321 ms 86832 KB Output is correct
89 Correct 1360 ms 86764 KB Output is correct
90 Correct 1371 ms 86952 KB Output is correct
91 Correct 1417 ms 86904 KB Output is correct
92 Correct 1400 ms 86920 KB Output is correct
93 Correct 1324 ms 86876 KB Output is correct
94 Correct 1331 ms 86964 KB Output is correct
95 Correct 1307 ms 86760 KB Output is correct
96 Correct 1335 ms 86804 KB Output is correct
97 Correct 1349 ms 86884 KB Output is correct
98 Correct 1321 ms 86844 KB Output is correct
99 Correct 1322 ms 86760 KB Output is correct
100 Correct 620 ms 45692 KB Output is correct
101 Correct 615 ms 45596 KB Output is correct
102 Correct 622 ms 45620 KB Output is correct
103 Correct 631 ms 45620 KB Output is correct
104 Correct 653 ms 45688 KB Output is correct
105 Correct 908 ms 86788 KB Output is correct
106 Correct 947 ms 86684 KB Output is correct
107 Correct 891 ms 86812 KB Output is correct
108 Correct 882 ms 86664 KB Output is correct
109 Correct 875 ms 86672 KB Output is correct
110 Correct 1053 ms 86824 KB Output is correct
111 Correct 1070 ms 86820 KB Output is correct
112 Correct 1058 ms 86840 KB Output is correct
113 Correct 1057 ms 86976 KB Output is correct
114 Correct 1064 ms 86780 KB Output is correct
115 Correct 1091 ms 86816 KB Output is correct
116 Correct 1068 ms 86792 KB Output is correct
117 Correct 1084 ms 86796 KB Output is correct
118 Correct 1064 ms 86740 KB Output is correct
119 Correct 1083 ms 86908 KB Output is correct
120 Correct 2 ms 512 KB Output is correct
121 Correct 2 ms 512 KB Output is correct
122 Incorrect 1349 ms 86744 KB Output isn't correct
123 Halted 0 ms 0 KB -