답안 #1041404

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1041404 2024-08-02T03:02:26 Z wibulord Bulldozer (JOI17_bulldozer) C++14
100 / 100
564 ms 52416 KB
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define fi first
#define se second
#define pb emplace_back
#define ii pair<int, int>
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define sz(s) (int)((s).size())
#define all(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define F0R(i, b) for (int i = 0, _b = (b); i < _b; ++i)
#define FORd(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define F0Rd(i, b) for (int i = (b)-1; i >= 0; i--)
#define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std;

template<typename T1,typename T2> bool ckmax(T1 &x,const T2 &y){if(x<y){x=y; return 1;} return 0;}
template<typename T1,typename T2> bool ckmin(T1 &x,const T2 &y){if(y<x){x=y; return 1;} return 0;}

const int MOD = (int)1e9 + 7;
const int mod = 998244353;
const int N = 2e3 + 10, M = 14;
const long long INF = (long long)4e18 + 11;

/*
     /\_/\
    (= ._.)
    / >?  \>$
*/

int n;
struct Pt{
    int x, y, w;
    Pt(){}
    Pt(int _x, int _y, int _w){
        x = _x, y = _y, w = _w;
    }
    bool operator < (const Pt &p) const{
        return x != p.x ? x < p.x : y < p.y;
    }
}A[N];

struct Line{
    long long A, B;
    int id1, id2;
    Line(){}
    Line(long long _A, long long _B, int _id1, int _id2){
        A = _A, B = _B, id1 = _id1, id2 = _id2;
    }
    bool operator < (const Line &p) const{
        return A * p.B != B * p.A ? A * p.B < B * p.A : make_pair(id1, id2) < make_pair(p.id1, p.id2);
    }
};
vector<Line> Slope;

int pos[N];
struct Node{
    long long sum, L, R, mx;
    Node(){
        sum = 0;
        L = R = mx = -INF;
    }
}st[MASK(M)];

void update(int i, int l, int r, int p, long long d){
    while(l < r){
        int m = (l + r) >> 1;
        if(p <= m) r = m, i = i<<1;
        else l = m+1, i = i<<1|1;
    }
    st[i].sum = st[i].L = st[i].R = st[i].mx = d;
    while(i > 1){
        i >>= 1;
        st[i].sum = st[i<<1].sum + st[i<<1|1].sum;
        st[i].L = max(st[i<<1].L, st[i<<1].sum + st[i<<1|1].L);
        st[i].R = max(st[i<<1|1].R, st[i<<1|1].sum + st[i<<1].R);
        st[i].mx = max({st[i<<1].mx, st[i<<1|1].mx, st[i<<1].R + st[i<<1|1].L});
    }
}


void sol(void){
    cin >> n;
    FOR(i, 1, n){
        int x, y, w; cin >> x >> y >> w;
        A[i] = Pt(x, y, w);
    }
    sort(A+1,A+n+1);
    FOR(i, 1, n) FOR(j, i+1, n){
        Line tmp = Line(A[j].x - A[i].x, A[j].y - A[i].y, i, j);
        Slope.push_back(tmp);
    }
    sort(all(Slope));
    FOR(i, 1, n){
        pos[i] = i;
        update(1, 1, n, i, A[i].w);
    }
//    FOR(i, 1, n) cout << A[i].w << " \n"[i == n];
    long long ans = max(0LL, st[1].mx);

    int m = sz(Slope) - 1, j = 0;
    for(int i = 0; i <= m; i++) {
        while(j <= m && Slope[i].A * Slope[j].B == Slope[i].B * Slope[j].A){
            update(1, 1, n, pos[Slope[j].id1], A[Slope[j].id2].w);
            update(1, 1, n, pos[Slope[j].id2], A[Slope[j].id1].w);
            swap(pos[Slope[j].id1], pos[Slope[j].id2]);
            ++j;
        }
        i = j - 1;
        ans = max(ans, st[1].mx);
    }
    cout << ans << '\n';
}

signed main(void){
    #define TASK "nhap"
    if(fopen(TASK".inp", "r")){
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t = 1;
//    cin >> t;
    while(t--) sol();
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:120:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  120 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bulldozer.cpp:121:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  121 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1112 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 856 KB Output is correct
12 Correct 0 ms 860 KB Output is correct
13 Correct 0 ms 860 KB Output is correct
14 Correct 0 ms 860 KB Output is correct
15 Correct 0 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 2 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 0 ms 860 KB Output is correct
13 Correct 0 ms 860 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 0 ms 860 KB Output is correct
16 Correct 0 ms 860 KB Output is correct
17 Correct 0 ms 860 KB Output is correct
18 Correct 0 ms 860 KB Output is correct
19 Correct 0 ms 860 KB Output is correct
20 Correct 0 ms 856 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 2 ms 1116 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1116 KB Output is correct
26 Correct 1 ms 1116 KB Output is correct
27 Correct 1 ms 1116 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 1 ms 1116 KB Output is correct
30 Correct 1 ms 1116 KB Output is correct
31 Correct 1 ms 1116 KB Output is correct
32 Correct 1 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 2 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 0 ms 860 KB Output is correct
13 Correct 0 ms 860 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 0 ms 860 KB Output is correct
16 Correct 0 ms 860 KB Output is correct
17 Correct 0 ms 860 KB Output is correct
18 Correct 0 ms 860 KB Output is correct
19 Correct 0 ms 860 KB Output is correct
20 Correct 0 ms 856 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 2 ms 1116 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1116 KB Output is correct
26 Correct 1 ms 1116 KB Output is correct
27 Correct 1 ms 1116 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 1 ms 1116 KB Output is correct
30 Correct 1 ms 1116 KB Output is correct
31 Correct 1 ms 1116 KB Output is correct
32 Correct 1 ms 1116 KB Output is correct
33 Correct 504 ms 51048 KB Output is correct
34 Correct 494 ms 52368 KB Output is correct
35 Correct 497 ms 51904 KB Output is correct
36 Correct 491 ms 50372 KB Output is correct
37 Correct 498 ms 51652 KB Output is correct
38 Correct 492 ms 50884 KB Output is correct
39 Correct 494 ms 51136 KB Output is correct
40 Correct 494 ms 51648 KB Output is correct
41 Correct 492 ms 50880 KB Output is correct
42 Correct 501 ms 50372 KB Output is correct
43 Correct 498 ms 51396 KB Output is correct
44 Correct 490 ms 51140 KB Output is correct
45 Correct 506 ms 51904 KB Output is correct
46 Correct 503 ms 50884 KB Output is correct
47 Correct 508 ms 50628 KB Output is correct
48 Correct 528 ms 52160 KB Output is correct
49 Correct 499 ms 50624 KB Output is correct
50 Correct 503 ms 51396 KB Output is correct
51 Correct 505 ms 51648 KB Output is correct
52 Correct 494 ms 50368 KB Output is correct
53 Correct 494 ms 51120 KB Output is correct
54 Correct 489 ms 51652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 2 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 0 ms 860 KB Output is correct
13 Correct 0 ms 860 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 0 ms 860 KB Output is correct
16 Correct 0 ms 860 KB Output is correct
17 Correct 0 ms 860 KB Output is correct
18 Correct 0 ms 860 KB Output is correct
19 Correct 0 ms 860 KB Output is correct
20 Correct 0 ms 856 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 2 ms 1116 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1116 KB Output is correct
26 Correct 1 ms 1116 KB Output is correct
27 Correct 1 ms 1116 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 1 ms 1116 KB Output is correct
30 Correct 1 ms 1116 KB Output is correct
31 Correct 1 ms 1116 KB Output is correct
32 Correct 1 ms 1116 KB Output is correct
33 Correct 504 ms 51048 KB Output is correct
34 Correct 494 ms 52368 KB Output is correct
35 Correct 497 ms 51904 KB Output is correct
36 Correct 491 ms 50372 KB Output is correct
37 Correct 498 ms 51652 KB Output is correct
38 Correct 492 ms 50884 KB Output is correct
39 Correct 494 ms 51136 KB Output is correct
40 Correct 494 ms 51648 KB Output is correct
41 Correct 492 ms 50880 KB Output is correct
42 Correct 501 ms 50372 KB Output is correct
43 Correct 498 ms 51396 KB Output is correct
44 Correct 490 ms 51140 KB Output is correct
45 Correct 506 ms 51904 KB Output is correct
46 Correct 503 ms 50884 KB Output is correct
47 Correct 508 ms 50628 KB Output is correct
48 Correct 528 ms 52160 KB Output is correct
49 Correct 499 ms 50624 KB Output is correct
50 Correct 503 ms 51396 KB Output is correct
51 Correct 505 ms 51648 KB Output is correct
52 Correct 494 ms 50368 KB Output is correct
53 Correct 494 ms 51120 KB Output is correct
54 Correct 489 ms 51652 KB Output is correct
55 Correct 498 ms 51392 KB Output is correct
56 Correct 505 ms 51908 KB Output is correct
57 Correct 506 ms 51140 KB Output is correct
58 Correct 520 ms 51904 KB Output is correct
59 Correct 503 ms 50884 KB Output is correct
60 Correct 504 ms 51140 KB Output is correct
61 Correct 498 ms 51140 KB Output is correct
62 Correct 510 ms 50880 KB Output is correct
63 Correct 528 ms 52164 KB Output is correct
64 Correct 504 ms 51648 KB Output is correct
65 Correct 500 ms 50372 KB Output is correct
66 Correct 515 ms 52352 KB Output is correct
67 Correct 497 ms 52160 KB Output is correct
68 Correct 501 ms 51376 KB Output is correct
69 Correct 500 ms 50372 KB Output is correct
70 Correct 504 ms 51648 KB Output is correct
71 Correct 503 ms 50372 KB Output is correct
72 Correct 515 ms 51140 KB Output is correct
73 Correct 504 ms 51140 KB Output is correct
74 Correct 533 ms 50372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1112 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 856 KB Output is correct
12 Correct 0 ms 860 KB Output is correct
13 Correct 0 ms 860 KB Output is correct
14 Correct 0 ms 860 KB Output is correct
15 Correct 0 ms 860 KB Output is correct
16 Correct 1 ms 1112 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 2 ms 1116 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 2 ms 1116 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Correct 0 ms 860 KB Output is correct
28 Correct 0 ms 860 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 0 ms 860 KB Output is correct
31 Correct 0 ms 860 KB Output is correct
32 Correct 0 ms 860 KB Output is correct
33 Correct 0 ms 860 KB Output is correct
34 Correct 0 ms 860 KB Output is correct
35 Correct 0 ms 856 KB Output is correct
36 Correct 1 ms 1116 KB Output is correct
37 Correct 2 ms 1116 KB Output is correct
38 Correct 1 ms 1116 KB Output is correct
39 Correct 1 ms 1116 KB Output is correct
40 Correct 1 ms 1116 KB Output is correct
41 Correct 1 ms 1116 KB Output is correct
42 Correct 1 ms 1116 KB Output is correct
43 Correct 1 ms 1116 KB Output is correct
44 Correct 1 ms 1116 KB Output is correct
45 Correct 1 ms 1116 KB Output is correct
46 Correct 1 ms 1116 KB Output is correct
47 Correct 1 ms 1116 KB Output is correct
48 Correct 504 ms 51048 KB Output is correct
49 Correct 494 ms 52368 KB Output is correct
50 Correct 497 ms 51904 KB Output is correct
51 Correct 491 ms 50372 KB Output is correct
52 Correct 498 ms 51652 KB Output is correct
53 Correct 492 ms 50884 KB Output is correct
54 Correct 494 ms 51136 KB Output is correct
55 Correct 494 ms 51648 KB Output is correct
56 Correct 492 ms 50880 KB Output is correct
57 Correct 501 ms 50372 KB Output is correct
58 Correct 498 ms 51396 KB Output is correct
59 Correct 490 ms 51140 KB Output is correct
60 Correct 506 ms 51904 KB Output is correct
61 Correct 503 ms 50884 KB Output is correct
62 Correct 508 ms 50628 KB Output is correct
63 Correct 528 ms 52160 KB Output is correct
64 Correct 499 ms 50624 KB Output is correct
65 Correct 503 ms 51396 KB Output is correct
66 Correct 505 ms 51648 KB Output is correct
67 Correct 494 ms 50368 KB Output is correct
68 Correct 494 ms 51120 KB Output is correct
69 Correct 489 ms 51652 KB Output is correct
70 Correct 498 ms 51392 KB Output is correct
71 Correct 505 ms 51908 KB Output is correct
72 Correct 506 ms 51140 KB Output is correct
73 Correct 520 ms 51904 KB Output is correct
74 Correct 503 ms 50884 KB Output is correct
75 Correct 504 ms 51140 KB Output is correct
76 Correct 498 ms 51140 KB Output is correct
77 Correct 510 ms 50880 KB Output is correct
78 Correct 528 ms 52164 KB Output is correct
79 Correct 504 ms 51648 KB Output is correct
80 Correct 500 ms 50372 KB Output is correct
81 Correct 515 ms 52352 KB Output is correct
82 Correct 497 ms 52160 KB Output is correct
83 Correct 501 ms 51376 KB Output is correct
84 Correct 500 ms 50372 KB Output is correct
85 Correct 504 ms 51648 KB Output is correct
86 Correct 503 ms 50372 KB Output is correct
87 Correct 515 ms 51140 KB Output is correct
88 Correct 504 ms 51140 KB Output is correct
89 Correct 533 ms 50372 KB Output is correct
90 Correct 512 ms 52152 KB Output is correct
91 Correct 519 ms 51128 KB Output is correct
92 Correct 501 ms 51140 KB Output is correct
93 Correct 509 ms 51908 KB Output is correct
94 Correct 564 ms 51392 KB Output is correct
95 Correct 501 ms 51904 KB Output is correct
96 Correct 505 ms 50368 KB Output is correct
97 Correct 519 ms 51140 KB Output is correct
98 Correct 502 ms 51648 KB Output is correct
99 Correct 497 ms 52152 KB Output is correct
100 Correct 393 ms 51636 KB Output is correct
101 Correct 388 ms 50880 KB Output is correct
102 Correct 394 ms 51648 KB Output is correct
103 Correct 397 ms 52164 KB Output is correct
104 Correct 397 ms 50624 KB Output is correct
105 Correct 438 ms 51800 KB Output is correct
106 Correct 415 ms 51908 KB Output is correct
107 Correct 412 ms 51908 KB Output is correct
108 Correct 416 ms 50628 KB Output is correct
109 Correct 428 ms 51648 KB Output is correct
110 Correct 483 ms 50500 KB Output is correct
111 Correct 495 ms 51812 KB Output is correct
112 Correct 485 ms 51908 KB Output is correct
113 Correct 474 ms 50880 KB Output is correct
114 Correct 480 ms 51908 KB Output is correct
115 Correct 483 ms 51640 KB Output is correct
116 Correct 485 ms 51396 KB Output is correct
117 Correct 490 ms 52160 KB Output is correct
118 Correct 473 ms 51396 KB Output is correct
119 Correct 472 ms 50628 KB Output is correct
120 Correct 1 ms 856 KB Output is correct
121 Correct 0 ms 860 KB Output is correct
122 Correct 509 ms 50932 KB Output is correct
123 Correct 509 ms 52416 KB Output is correct
124 Correct 512 ms 51080 KB Output is correct
125 Correct 511 ms 52160 KB Output is correct
126 Correct 507 ms 52160 KB Output is correct
127 Correct 533 ms 50884 KB Output is correct
128 Correct 542 ms 50880 KB Output is correct
129 Correct 501 ms 50880 KB Output is correct
130 Correct 511 ms 50880 KB Output is correct
131 Correct 505 ms 51140 KB Output is correct
132 Correct 526 ms 51648 KB Output is correct
133 Correct 509 ms 51900 KB Output is correct