답안 #1040530

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1040530 2024-08-01T06:57:02 Z thangnguyen Bulldozer (JOI17_bulldozer) C++14
100 / 100
694 ms 51884 KB
#include <bits/stdc++.h>
#define ii pair<int,int>
#define fi first
#define se second
#define ll long long
#define TASKS "i."
#define fast ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
#define all(x) x.begin(),x.end()
#define FORU(i,a,b) for(int i = a, _b = b; i <= _b ; i++)
#define FORD(i,a,b) for(int i = a, _b = b; i >= _b ; i--)
#define endl "\n"

using namespace std;
const int maxn = 2000 ;
int n ;
struct mineinfo
{
    int x, y,z ;
    void inp() {cin >> x >> y >> z ; }
    bool operator < (const mineinfo &o)
    {
        if(x == o.x) return y > o.y ;
        return x < o.x ;
    }
} a[maxn+1];

struct lineinfo
{
    ll a,b; int id1, id2 ;
    bool operator < (const lineinfo &x)
    {
        if(x.a * a == 0)
        {
            if(a + x.a == 0) return make_pair(id1,id2) < make_pair(x.id1,x.id2) ;
            return (a == 0) ;
        }
        if(a == x.a && b == x.b) return make_pair(id1,id2) < make_pair(x.id1,x.id2) ;
        return x.a * b < a * x.b ;
    }
    void get(ii A, ii B, int i, int j)
    {
        a = B.fi - A.fi , b = B.se - A.se ;
        int c = abs(__gcd(a,b)) ;
        a/=c, b/= c ;
        id1 = i, id2 = j ;
    }
} ;
vector<lineinfo> line ;
int id[maxn+1] ;
bool kt[maxn+1] ;

struct nodeinfo
{
    ll sum, mx, mxl, mxr ;
} ;

struct SegmentTree
{
    nodeinfo val[maxn*4] ;
    void cal(nodeinfo &x, nodeinfo c1, nodeinfo c2)
    {
        x.sum = c1.sum + c2.sum ;
        x.mxl = max(c1.mxl, c1.sum + c2.mxl) ;
        x.mxr = max(c2.mxr, c2.sum + c1.mxr) ;
        x.mx = max({c1.mx,c2.mx,c1.mxr + c2.mxl}) ;
    }
    void update(int id, int v)
    {
        int x = 1, L = 1, R = n ;
        while(L < R)
        {
            int mid = (L+R)>>1;
            if(id <= mid) x = x<<1,R = mid ;
            else x = x<<1|1,L = mid + 1 ;
        }
        val[x].sum = v , val[x].mxl = v, val[x].mxr = v ;
        if(v > 0) val[x].mx = v;
        x>>=1 ;
        while(x)
        {
            cal(val[x],val[x<<1],val[x<<1|1])  ;
            x>>=1 ;
        }
        return ;
    }
    ll getans()
    {
        return val[1].mx ;
    }
}tree;

int main()
{
    fast ;
//    freopen(TASKS"INP","r",stdin) ;
//    freopen(TASKS"OUT","w",stdout) ;
    cin >> n ;
    FORU(i,1,n) a[i].inp();
    sort(&a[1],&a[n+1])  ;

    FORU(i,1,n)
    {
        tree.update(i,a[i].z) ;
        ii A = {a[i].x,a[i].y} , B ;
        id[i] = i ;
        lineinfo l ;
        FORU(j,i+1,n)
        {
            B = {a[j].x,a[j].y} ;
            l.get(A,B,i,j) ;
            line.push_back(l) ;
        }
    }
    sort(all(line)) ;
    ll ans = tree.getans() ;
    FORU(i,0,line.size() - 1)
    {
        if(i == 7)
            int tor = 1;
        lineinfo l = line[i];
        tree.update(id[l.id2],a[l.id1].z) ;
        tree.update(id[l.id1],a[l.id2].z) ;
        swap(id[l.id1],id[l.id2]) ;
//        FORU(i,1,n) cout << id[i] << ' ' ;
//        cout << endl ;
        if(i + 1 < line.size() && (line[i+1].a == l.a && line[i+1].b ==l.b))
        {
            continue ;
        }
        ans = max(ans,tree.getans()) ;
    }
    cout << ans;
    return 0 ;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:119:17: warning: unused variable 'tor' [-Wunused-variable]
  119 |             int tor = 1;
      |                 ^~~
bulldozer.cpp:126:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<lineinfo>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  126 |         if(i + 1 < line.size() && (line[i+1].a == l.a && line[i+1].b ==l.b))
      |            ~~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 624 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 720 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 2 ms 600 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 624 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 720 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 2 ms 600 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 647 ms 50340 KB Output is correct
34 Correct 652 ms 51148 KB Output is correct
35 Correct 684 ms 51872 KB Output is correct
36 Correct 677 ms 50788 KB Output is correct
37 Correct 670 ms 49832 KB Output is correct
38 Correct 646 ms 50088 KB Output is correct
39 Correct 651 ms 51240 KB Output is correct
40 Correct 646 ms 50092 KB Output is correct
41 Correct 651 ms 50288 KB Output is correct
42 Correct 644 ms 50600 KB Output is correct
43 Correct 624 ms 50344 KB Output is correct
44 Correct 623 ms 50592 KB Output is correct
45 Correct 643 ms 51300 KB Output is correct
46 Correct 627 ms 51364 KB Output is correct
47 Correct 620 ms 51712 KB Output is correct
48 Correct 622 ms 50852 KB Output is correct
49 Correct 664 ms 51368 KB Output is correct
50 Correct 621 ms 50084 KB Output is correct
51 Correct 626 ms 50488 KB Output is correct
52 Correct 620 ms 50856 KB Output is correct
53 Correct 619 ms 50856 KB Output is correct
54 Correct 618 ms 50088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 624 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 720 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 2 ms 600 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 647 ms 50340 KB Output is correct
34 Correct 652 ms 51148 KB Output is correct
35 Correct 684 ms 51872 KB Output is correct
36 Correct 677 ms 50788 KB Output is correct
37 Correct 670 ms 49832 KB Output is correct
38 Correct 646 ms 50088 KB Output is correct
39 Correct 651 ms 51240 KB Output is correct
40 Correct 646 ms 50092 KB Output is correct
41 Correct 651 ms 50288 KB Output is correct
42 Correct 644 ms 50600 KB Output is correct
43 Correct 624 ms 50344 KB Output is correct
44 Correct 623 ms 50592 KB Output is correct
45 Correct 643 ms 51300 KB Output is correct
46 Correct 627 ms 51364 KB Output is correct
47 Correct 620 ms 51712 KB Output is correct
48 Correct 622 ms 50852 KB Output is correct
49 Correct 664 ms 51368 KB Output is correct
50 Correct 621 ms 50084 KB Output is correct
51 Correct 626 ms 50488 KB Output is correct
52 Correct 620 ms 50856 KB Output is correct
53 Correct 619 ms 50856 KB Output is correct
54 Correct 618 ms 50088 KB Output is correct
55 Correct 649 ms 50540 KB Output is correct
56 Correct 646 ms 50500 KB Output is correct
57 Correct 673 ms 49832 KB Output is correct
58 Correct 681 ms 51620 KB Output is correct
59 Correct 670 ms 51216 KB Output is correct
60 Correct 648 ms 51620 KB Output is correct
61 Correct 648 ms 51356 KB Output is correct
62 Correct 694 ms 51608 KB Output is correct
63 Correct 647 ms 51616 KB Output is correct
64 Correct 656 ms 50344 KB Output is correct
65 Correct 649 ms 51364 KB Output is correct
66 Correct 654 ms 50856 KB Output is correct
67 Correct 653 ms 50856 KB Output is correct
68 Correct 651 ms 51096 KB Output is correct
69 Correct 647 ms 50600 KB Output is correct
70 Correct 673 ms 50596 KB Output is correct
71 Correct 651 ms 50856 KB Output is correct
72 Correct 650 ms 51060 KB Output is correct
73 Correct 668 ms 51116 KB Output is correct
74 Correct 665 ms 51204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 624 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 720 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 2 ms 600 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 1 ms 600 KB Output is correct
47 Correct 2 ms 604 KB Output is correct
48 Correct 647 ms 50340 KB Output is correct
49 Correct 652 ms 51148 KB Output is correct
50 Correct 684 ms 51872 KB Output is correct
51 Correct 677 ms 50788 KB Output is correct
52 Correct 670 ms 49832 KB Output is correct
53 Correct 646 ms 50088 KB Output is correct
54 Correct 651 ms 51240 KB Output is correct
55 Correct 646 ms 50092 KB Output is correct
56 Correct 651 ms 50288 KB Output is correct
57 Correct 644 ms 50600 KB Output is correct
58 Correct 624 ms 50344 KB Output is correct
59 Correct 623 ms 50592 KB Output is correct
60 Correct 643 ms 51300 KB Output is correct
61 Correct 627 ms 51364 KB Output is correct
62 Correct 620 ms 51712 KB Output is correct
63 Correct 622 ms 50852 KB Output is correct
64 Correct 664 ms 51368 KB Output is correct
65 Correct 621 ms 50084 KB Output is correct
66 Correct 626 ms 50488 KB Output is correct
67 Correct 620 ms 50856 KB Output is correct
68 Correct 619 ms 50856 KB Output is correct
69 Correct 618 ms 50088 KB Output is correct
70 Correct 649 ms 50540 KB Output is correct
71 Correct 646 ms 50500 KB Output is correct
72 Correct 673 ms 49832 KB Output is correct
73 Correct 681 ms 51620 KB Output is correct
74 Correct 670 ms 51216 KB Output is correct
75 Correct 648 ms 51620 KB Output is correct
76 Correct 648 ms 51356 KB Output is correct
77 Correct 694 ms 51608 KB Output is correct
78 Correct 647 ms 51616 KB Output is correct
79 Correct 656 ms 50344 KB Output is correct
80 Correct 649 ms 51364 KB Output is correct
81 Correct 654 ms 50856 KB Output is correct
82 Correct 653 ms 50856 KB Output is correct
83 Correct 651 ms 51096 KB Output is correct
84 Correct 647 ms 50600 KB Output is correct
85 Correct 673 ms 50596 KB Output is correct
86 Correct 651 ms 50856 KB Output is correct
87 Correct 650 ms 51060 KB Output is correct
88 Correct 668 ms 51116 KB Output is correct
89 Correct 665 ms 51204 KB Output is correct
90 Correct 663 ms 49828 KB Output is correct
91 Correct 654 ms 51876 KB Output is correct
92 Correct 653 ms 50340 KB Output is correct
93 Correct 643 ms 50340 KB Output is correct
94 Correct 673 ms 51724 KB Output is correct
95 Correct 643 ms 50344 KB Output is correct
96 Correct 650 ms 51364 KB Output is correct
97 Correct 659 ms 50092 KB Output is correct
98 Correct 658 ms 50596 KB Output is correct
99 Correct 643 ms 50344 KB Output is correct
100 Correct 430 ms 51784 KB Output is correct
101 Correct 427 ms 50108 KB Output is correct
102 Correct 418 ms 50620 KB Output is correct
103 Correct 451 ms 51136 KB Output is correct
104 Correct 433 ms 50368 KB Output is correct
105 Correct 480 ms 51136 KB Output is correct
106 Correct 481 ms 50612 KB Output is correct
107 Correct 485 ms 50880 KB Output is correct
108 Correct 482 ms 50532 KB Output is correct
109 Correct 483 ms 50616 KB Output is correct
110 Correct 537 ms 50344 KB Output is correct
111 Correct 534 ms 51036 KB Output is correct
112 Correct 537 ms 51628 KB Output is correct
113 Correct 549 ms 51080 KB Output is correct
114 Correct 551 ms 51884 KB Output is correct
115 Correct 550 ms 50860 KB Output is correct
116 Correct 540 ms 50872 KB Output is correct
117 Correct 536 ms 50360 KB Output is correct
118 Correct 560 ms 50348 KB Output is correct
119 Correct 570 ms 50604 KB Output is correct
120 Correct 0 ms 344 KB Output is correct
121 Correct 0 ms 348 KB Output is correct
122 Correct 582 ms 50732 KB Output is correct
123 Correct 581 ms 50604 KB Output is correct
124 Correct 587 ms 50324 KB Output is correct
125 Correct 576 ms 51880 KB Output is correct
126 Correct 580 ms 50916 KB Output is correct
127 Correct 575 ms 49828 KB Output is correct
128 Correct 578 ms 50696 KB Output is correct
129 Correct 575 ms 51880 KB Output is correct
130 Correct 595 ms 51368 KB Output is correct
131 Correct 581 ms 50848 KB Output is correct
132 Correct 608 ms 51620 KB Output is correct
133 Correct 575 ms 50104 KB Output is correct