답안 #1041402

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1041402 2024-08-02T02:52:31 Z wibulord Bulldozer (JOI17_bulldozer) C++14
75 / 100
522 ms 50468 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;
    }
};
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);
    }
    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:119:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  119 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
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".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 1 ms 1248 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Correct 1 ms 1116 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 1180 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1112 KB Output is correct
11 Correct 0 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 0 ms 860 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 1 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 1 ms 1112 KB Output is correct
20 Correct 0 ms 860 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1112 KB Output is correct
23 Correct 1 ms 1112 KB Output is correct
24 Correct 2 ms 1372 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 1112 KB Output is correct
31 Correct 1 ms 1116 KB Output is correct
32 Correct 1 ms 1368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 1 ms 1248 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Correct 1 ms 1116 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 1180 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1112 KB Output is correct
11 Correct 0 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 0 ms 860 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 1 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 1 ms 1112 KB Output is correct
20 Correct 0 ms 860 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1112 KB Output is correct
23 Correct 1 ms 1112 KB Output is correct
24 Correct 2 ms 1372 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 1112 KB Output is correct
31 Correct 1 ms 1116 KB Output is correct
32 Correct 1 ms 1368 KB Output is correct
33 Correct 504 ms 50356 KB Output is correct
34 Correct 499 ms 50372 KB Output is correct
35 Correct 499 ms 50344 KB Output is correct
36 Correct 504 ms 50372 KB Output is correct
37 Correct 489 ms 50368 KB Output is correct
38 Correct 495 ms 50368 KB Output is correct
39 Correct 519 ms 50368 KB Output is correct
40 Correct 502 ms 50468 KB Output is correct
41 Correct 510 ms 50360 KB Output is correct
42 Correct 522 ms 50372 KB Output is correct
43 Correct 490 ms 50372 KB Output is correct
44 Correct 504 ms 50368 KB Output is correct
45 Correct 500 ms 50360 KB Output is correct
46 Correct 507 ms 50372 KB Output is correct
47 Correct 502 ms 50364 KB Output is correct
48 Correct 514 ms 50364 KB Output is correct
49 Correct 491 ms 50372 KB Output is correct
50 Correct 496 ms 50352 KB Output is correct
51 Correct 513 ms 50352 KB Output is correct
52 Correct 496 ms 50360 KB Output is correct
53 Correct 488 ms 50360 KB Output is correct
54 Correct 485 ms 50364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 1 ms 1248 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Correct 1 ms 1116 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 1180 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1112 KB Output is correct
11 Correct 0 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 0 ms 860 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 1 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 1 ms 1112 KB Output is correct
20 Correct 0 ms 860 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1112 KB Output is correct
23 Correct 1 ms 1112 KB Output is correct
24 Correct 2 ms 1372 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 1112 KB Output is correct
31 Correct 1 ms 1116 KB Output is correct
32 Correct 1 ms 1368 KB Output is correct
33 Correct 504 ms 50356 KB Output is correct
34 Correct 499 ms 50372 KB Output is correct
35 Correct 499 ms 50344 KB Output is correct
36 Correct 504 ms 50372 KB Output is correct
37 Correct 489 ms 50368 KB Output is correct
38 Correct 495 ms 50368 KB Output is correct
39 Correct 519 ms 50368 KB Output is correct
40 Correct 502 ms 50468 KB Output is correct
41 Correct 510 ms 50360 KB Output is correct
42 Correct 522 ms 50372 KB Output is correct
43 Correct 490 ms 50372 KB Output is correct
44 Correct 504 ms 50368 KB Output is correct
45 Correct 500 ms 50360 KB Output is correct
46 Correct 507 ms 50372 KB Output is correct
47 Correct 502 ms 50364 KB Output is correct
48 Correct 514 ms 50364 KB Output is correct
49 Correct 491 ms 50372 KB Output is correct
50 Correct 496 ms 50352 KB Output is correct
51 Correct 513 ms 50352 KB Output is correct
52 Correct 496 ms 50360 KB Output is correct
53 Correct 488 ms 50360 KB Output is correct
54 Correct 485 ms 50364 KB Output is correct
55 Correct 496 ms 50360 KB Output is correct
56 Correct 514 ms 50416 KB Output is correct
57 Correct 518 ms 50348 KB Output is correct
58 Correct 509 ms 50364 KB Output is correct
59 Correct 508 ms 50356 KB Output is correct
60 Correct 504 ms 50344 KB Output is correct
61 Correct 496 ms 50360 KB Output is correct
62 Correct 495 ms 50364 KB Output is correct
63 Correct 494 ms 50360 KB Output is correct
64 Correct 488 ms 50356 KB Output is correct
65 Correct 490 ms 50272 KB Output is correct
66 Correct 494 ms 50372 KB Output is correct
67 Correct 505 ms 50268 KB Output is correct
68 Correct 504 ms 50360 KB Output is correct
69 Correct 497 ms 50364 KB Output is correct
70 Correct 493 ms 50360 KB Output is correct
71 Correct 489 ms 50364 KB Output is correct
72 Correct 510 ms 50372 KB Output is correct
73 Correct 516 ms 50364 KB Output is correct
74 Correct 491 ms 50364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1368 KB Output isn't correct
2 Halted 0 ms 0 KB -