답안 #489656

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
489656 2021-11-23T14:56:56 Z Alexandruabcde Bulldozer (JOI17_bulldozer) C++14
100 / 100
1010 ms 50080 KB
#include <bits/stdc++.h>

using namespace std;

constexpr int NMAX = 2005;
typedef long long LL;
constexpr LL INF = 1000000000000000000;

int N;

struct punct {
    LL x, y;
    LL cost;
};

bool cmp (punct a, punct b) {
    return (a.x < b.x) || (a.x == b.x && a.y < b.y);
}

punct P[NMAX];

struct Panta {
    LL y, x;
    int ind_1, ind_2;
};

bool cmp_Panta (Panta a, Panta b) {
    if (a.y * b.x == b.y * a.x) {
        if (a.ind_1 == b.ind_1)
            return a.ind_2 < b.ind_2;
        return a.ind_1 < b.ind_1;
    }

    return (a.y * b.x < b.y * a.x);
}

vector <Panta> V;

int poz[NMAX];

struct Node {
    LL sum;
    LL pref, suff, best;
};
Node arbore[4*NMAX];

Node Combin (Node a, Node b) {
    Node rez;

    rez.sum = (a.sum + b.sum);
    rez.pref = max(a.pref, a.sum + b.pref);
    rez.suff = max(b.suff, b.sum + a.suff);
    rez.best = max(a.best, b.best);
    rez.best = max(rez.best, a.suff + b.pref);

    return rez;
}

void Update (int nod, int a, int b, int poz, LL val) {
    if (a == b) {
        arbore[nod].best = val;
        arbore[nod].pref = val;
        arbore[nod].suff = val;
        arbore[nod].sum = val;
        return;
    }

    int mij = (a + b) / 2;
    if (poz <= mij) Update(2*nod, a, mij, poz, val);
    else Update(2*nod+1, mij+1, b, poz, val);

    arbore[nod] = Combin(arbore[2*nod], arbore[2*nod+1]);
}

void Read () {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N;

    for (int i = 1; i <= N; ++ i )
        cin >> P[i].x >> P[i].y >> P[i].cost;
    sort(P+1, P+N+1, cmp);

    for (int i = 1; i <= N; ++ i )
        for (int j = i+1; j <= N; ++ j ) {
            Panta aux;
            aux.y = P[j].y - P[i].y;
            aux.x = P[j].x - P[i].x;
            aux.ind_1 = i;
            aux.ind_2 = j;
            V.push_back(aux);
        }
    sort(V.begin(), V.end(), cmp_Panta);
}

void Solve () {
    for (int i = 1; i <= N; ++ i ) {
        poz[i] = i;
        Update(1, 1, N, i, P[i].cost);
    }
    LL sol = max(0LL, arbore[1].best);

    for (int i = 0; i < V.size(); ++ i ) {
        int j = i;
        while (j < V.size() && V[i].y * V[j].x == V[i].x * V[j].y) {
            Update(1, 1, N, poz[V[j].ind_1], P[V[j].ind_2].cost);
            Update(1, 1, N, poz[V[j].ind_2], P[V[j].ind_1].cost);

            swap(poz[V[j].ind_1], poz[V[j].ind_2]);
            ++ j;
        }

        sol = max(sol, arbore[1].best);
        i = j-1;
    }

    cout << sol << '\n';
}

int main () {
    Read();
    Solve();

    return 0;
}

Compilation message

bulldozer.cpp: In function 'void Solve()':
bulldozer.cpp:104:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Panta>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |     for (int i = 0; i < V.size(); ++ i ) {
      |                     ~~^~~~~~~~~~
bulldozer.cpp:106:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Panta>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |         while (j < V.size() && V[i].y * V[j].x == V[i].x * V[j].y) {
      |                ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 2 ms 584 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 336 KB Output is correct
16 Correct 0 ms 208 KB Output is correct
17 Correct 0 ms 336 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 2 ms 588 KB Output is correct
22 Correct 2 ms 580 KB Output is correct
23 Correct 2 ms 588 KB Output is correct
24 Correct 2 ms 588 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 2 ms 588 KB Output is correct
27 Correct 2 ms 588 KB Output is correct
28 Correct 2 ms 588 KB Output is correct
29 Correct 2 ms 588 KB Output is correct
30 Correct 2 ms 588 KB Output is correct
31 Correct 2 ms 588 KB Output is correct
32 Correct 2 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 336 KB Output is correct
16 Correct 0 ms 208 KB Output is correct
17 Correct 0 ms 336 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 2 ms 588 KB Output is correct
22 Correct 2 ms 580 KB Output is correct
23 Correct 2 ms 588 KB Output is correct
24 Correct 2 ms 588 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 2 ms 588 KB Output is correct
27 Correct 2 ms 588 KB Output is correct
28 Correct 2 ms 588 KB Output is correct
29 Correct 2 ms 588 KB Output is correct
30 Correct 2 ms 588 KB Output is correct
31 Correct 2 ms 588 KB Output is correct
32 Correct 2 ms 588 KB Output is correct
33 Correct 928 ms 49804 KB Output is correct
34 Correct 1010 ms 49832 KB Output is correct
35 Correct 908 ms 49796 KB Output is correct
36 Correct 901 ms 49788 KB Output is correct
37 Correct 897 ms 49756 KB Output is correct
38 Correct 923 ms 49808 KB Output is correct
39 Correct 913 ms 49944 KB Output is correct
40 Correct 925 ms 49812 KB Output is correct
41 Correct 914 ms 49812 KB Output is correct
42 Correct 919 ms 49812 KB Output is correct
43 Correct 918 ms 49824 KB Output is correct
44 Correct 943 ms 49796 KB Output is correct
45 Correct 903 ms 49820 KB Output is correct
46 Correct 892 ms 49768 KB Output is correct
47 Correct 918 ms 49768 KB Output is correct
48 Correct 887 ms 49812 KB Output is correct
49 Correct 909 ms 49864 KB Output is correct
50 Correct 887 ms 49812 KB Output is correct
51 Correct 887 ms 49836 KB Output is correct
52 Correct 940 ms 49800 KB Output is correct
53 Correct 888 ms 49788 KB Output is correct
54 Correct 955 ms 49816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 336 KB Output is correct
16 Correct 0 ms 208 KB Output is correct
17 Correct 0 ms 336 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 2 ms 588 KB Output is correct
22 Correct 2 ms 580 KB Output is correct
23 Correct 2 ms 588 KB Output is correct
24 Correct 2 ms 588 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 2 ms 588 KB Output is correct
27 Correct 2 ms 588 KB Output is correct
28 Correct 2 ms 588 KB Output is correct
29 Correct 2 ms 588 KB Output is correct
30 Correct 2 ms 588 KB Output is correct
31 Correct 2 ms 588 KB Output is correct
32 Correct 2 ms 588 KB Output is correct
33 Correct 928 ms 49804 KB Output is correct
34 Correct 1010 ms 49832 KB Output is correct
35 Correct 908 ms 49796 KB Output is correct
36 Correct 901 ms 49788 KB Output is correct
37 Correct 897 ms 49756 KB Output is correct
38 Correct 923 ms 49808 KB Output is correct
39 Correct 913 ms 49944 KB Output is correct
40 Correct 925 ms 49812 KB Output is correct
41 Correct 914 ms 49812 KB Output is correct
42 Correct 919 ms 49812 KB Output is correct
43 Correct 918 ms 49824 KB Output is correct
44 Correct 943 ms 49796 KB Output is correct
45 Correct 903 ms 49820 KB Output is correct
46 Correct 892 ms 49768 KB Output is correct
47 Correct 918 ms 49768 KB Output is correct
48 Correct 887 ms 49812 KB Output is correct
49 Correct 909 ms 49864 KB Output is correct
50 Correct 887 ms 49812 KB Output is correct
51 Correct 887 ms 49836 KB Output is correct
52 Correct 940 ms 49800 KB Output is correct
53 Correct 888 ms 49788 KB Output is correct
54 Correct 955 ms 49816 KB Output is correct
55 Correct 892 ms 49800 KB Output is correct
56 Correct 905 ms 49768 KB Output is correct
57 Correct 940 ms 49812 KB Output is correct
58 Correct 910 ms 49764 KB Output is correct
59 Correct 896 ms 49792 KB Output is correct
60 Correct 906 ms 49888 KB Output is correct
61 Correct 904 ms 49760 KB Output is correct
62 Correct 917 ms 49800 KB Output is correct
63 Correct 888 ms 49736 KB Output is correct
64 Correct 882 ms 49832 KB Output is correct
65 Correct 898 ms 49872 KB Output is correct
66 Correct 894 ms 49860 KB Output is correct
67 Correct 874 ms 49844 KB Output is correct
68 Correct 881 ms 49812 KB Output is correct
69 Correct 880 ms 49812 KB Output is correct
70 Correct 920 ms 49752 KB Output is correct
71 Correct 894 ms 49820 KB Output is correct
72 Correct 901 ms 49832 KB Output is correct
73 Correct 893 ms 49720 KB Output is correct
74 Correct 900 ms 49812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 2 ms 584 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 2 ms 588 KB Output is correct
17 Correct 2 ms 588 KB Output is correct
18 Correct 2 ms 588 KB Output is correct
19 Correct 2 ms 588 KB Output is correct
20 Correct 2 ms 588 KB Output is correct
21 Correct 2 ms 588 KB Output is correct
22 Correct 2 ms 588 KB Output is correct
23 Correct 2 ms 588 KB Output is correct
24 Correct 2 ms 588 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 0 ms 336 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 336 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 0 ms 332 KB Output is correct
36 Correct 2 ms 588 KB Output is correct
37 Correct 2 ms 580 KB Output is correct
38 Correct 2 ms 588 KB Output is correct
39 Correct 2 ms 588 KB Output is correct
40 Correct 2 ms 588 KB Output is correct
41 Correct 2 ms 588 KB Output is correct
42 Correct 2 ms 588 KB Output is correct
43 Correct 2 ms 588 KB Output is correct
44 Correct 2 ms 588 KB Output is correct
45 Correct 2 ms 588 KB Output is correct
46 Correct 2 ms 588 KB Output is correct
47 Correct 2 ms 588 KB Output is correct
48 Correct 928 ms 49804 KB Output is correct
49 Correct 1010 ms 49832 KB Output is correct
50 Correct 908 ms 49796 KB Output is correct
51 Correct 901 ms 49788 KB Output is correct
52 Correct 897 ms 49756 KB Output is correct
53 Correct 923 ms 49808 KB Output is correct
54 Correct 913 ms 49944 KB Output is correct
55 Correct 925 ms 49812 KB Output is correct
56 Correct 914 ms 49812 KB Output is correct
57 Correct 919 ms 49812 KB Output is correct
58 Correct 918 ms 49824 KB Output is correct
59 Correct 943 ms 49796 KB Output is correct
60 Correct 903 ms 49820 KB Output is correct
61 Correct 892 ms 49768 KB Output is correct
62 Correct 918 ms 49768 KB Output is correct
63 Correct 887 ms 49812 KB Output is correct
64 Correct 909 ms 49864 KB Output is correct
65 Correct 887 ms 49812 KB Output is correct
66 Correct 887 ms 49836 KB Output is correct
67 Correct 940 ms 49800 KB Output is correct
68 Correct 888 ms 49788 KB Output is correct
69 Correct 955 ms 49816 KB Output is correct
70 Correct 892 ms 49800 KB Output is correct
71 Correct 905 ms 49768 KB Output is correct
72 Correct 940 ms 49812 KB Output is correct
73 Correct 910 ms 49764 KB Output is correct
74 Correct 896 ms 49792 KB Output is correct
75 Correct 906 ms 49888 KB Output is correct
76 Correct 904 ms 49760 KB Output is correct
77 Correct 917 ms 49800 KB Output is correct
78 Correct 888 ms 49736 KB Output is correct
79 Correct 882 ms 49832 KB Output is correct
80 Correct 898 ms 49872 KB Output is correct
81 Correct 894 ms 49860 KB Output is correct
82 Correct 874 ms 49844 KB Output is correct
83 Correct 881 ms 49812 KB Output is correct
84 Correct 880 ms 49812 KB Output is correct
85 Correct 920 ms 49752 KB Output is correct
86 Correct 894 ms 49820 KB Output is correct
87 Correct 901 ms 49832 KB Output is correct
88 Correct 893 ms 49720 KB Output is correct
89 Correct 900 ms 49812 KB Output is correct
90 Correct 892 ms 49744 KB Output is correct
91 Correct 876 ms 49988 KB Output is correct
92 Correct 885 ms 49784 KB Output is correct
93 Correct 882 ms 49768 KB Output is correct
94 Correct 873 ms 49812 KB Output is correct
95 Correct 879 ms 49812 KB Output is correct
96 Correct 884 ms 49784 KB Output is correct
97 Correct 889 ms 49816 KB Output is correct
98 Correct 873 ms 49764 KB Output is correct
99 Correct 881 ms 49844 KB Output is correct
100 Correct 738 ms 49812 KB Output is correct
101 Correct 744 ms 49736 KB Output is correct
102 Correct 733 ms 49788 KB Output is correct
103 Correct 748 ms 49788 KB Output is correct
104 Correct 743 ms 49816 KB Output is correct
105 Correct 782 ms 49836 KB Output is correct
106 Correct 767 ms 49724 KB Output is correct
107 Correct 760 ms 49812 KB Output is correct
108 Correct 785 ms 49940 KB Output is correct
109 Correct 758 ms 49812 KB Output is correct
110 Correct 839 ms 49740 KB Output is correct
111 Correct 850 ms 49812 KB Output is correct
112 Correct 854 ms 49688 KB Output is correct
113 Correct 828 ms 49768 KB Output is correct
114 Correct 849 ms 49788 KB Output is correct
115 Correct 836 ms 49680 KB Output is correct
116 Correct 846 ms 49752 KB Output is correct
117 Correct 848 ms 49832 KB Output is correct
118 Correct 827 ms 49788 KB Output is correct
119 Correct 838 ms 49812 KB Output is correct
120 Correct 0 ms 336 KB Output is correct
121 Correct 0 ms 336 KB Output is correct
122 Correct 883 ms 49888 KB Output is correct
123 Correct 905 ms 49884 KB Output is correct
124 Correct 893 ms 49980 KB Output is correct
125 Correct 890 ms 49836 KB Output is correct
126 Correct 868 ms 50080 KB Output is correct
127 Correct 891 ms 49748 KB Output is correct
128 Correct 881 ms 49824 KB Output is correct
129 Correct 898 ms 49712 KB Output is correct
130 Correct 893 ms 49876 KB Output is correct
131 Correct 892 ms 49716 KB Output is correct
132 Correct 887 ms 49904 KB Output is correct
133 Correct 884 ms 49856 KB Output is correct