답안 #1077809

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1077809 2024-08-27T09:18:53 Z danikoynov Bulldozer (JOI17_bulldozer) C++14
25 / 100
2000 ms 604 KB
#include<bits/stdc++.h>
#define endl '\n'
    
using namespace std;
typedef long long ll;
    
struct Point
{
    ll x, y;
    
    Point(ll _x = 0, ll _y = 0)
    {
        x = _x;
        y = _y;
    }
    
    void input()
    {
        cin >> x >> y;
    }
};
    
const int MAXN = 2010;
int n;
pair < Point, ll > spot[MAXN];
void input()
{
    cin >> n;
    for (int i = 1; i <= n; i ++)
    {
        spot[i].first.input();
        cin >> spot[i].second;
    }
}
    
ll signed_area(Point A, Point B, Point C) /// returns signed area * 2
{
    ll area = (B.x - A.x) * (A.y + B.y) +
                (C.x - B.x) * (B.y + C.y) +
                    (A.x - C.x) * (C.y + A.y);
    return area;
}
    
int orient(Point A, Point B, Point C)
{
    
    ll area = signed_area(A, B, C);
    
    if (area > 0)
        return 1;
    if (area < 0)
        return -1;
    assert(area != 0);
    return 0;
}


bool cmp(pair < Point, ll > p1, pair < Point, ll > p2)
{
    return p1.first.x < p2.first.x;
}   
void simulate()
{
    
    bool all_x = true;
    for (int i = 1; i <= n; i ++)
        if (spot[i].first.y != 0)
            all_x = false;
    ll result = 0;
    if (all_x)
    {
        sort(spot + 1, spot + n + 1, cmp);
        for (int i = 1; i <= n; i ++)
        {
            ll sum = 0;
            for (int j = i; j <= n; j ++)
            {
                sum += spot[j].second;
                result = max(result, sum);
            }
        }
        cout << result << endl;
        return;
    }

    if (n == 1)
    {
        result = max(result, spot[1].second);
    }
    if (n == 2)
    {
        result = max(result, spot[1].second);
        result = max(result, spot[2].second);
        result = max(result, spot[1].second + spot[2].second);
    }
    for (int i = 1; i <= n; i ++)
        for (int j = i + 1; j <= n; j ++)
        {
            vector < pair < ll, ll > > pos, neg;
            for (int k = 1; k <= n; k ++)
            {
                if (k == i || k == j)
                    continue;
                ll area = signed_area(spot[i].first, 
                                        spot[j].first, 
                                        spot[k].first);
                /**if (i == 3 && j == 4)
                {
                    cout << "pair with " << k << " area " << area << " value " << spot[k].second << endl;
                }*/
                assert(area != 0);
                if (area > 0)
                    pos.push_back({area, spot[k].second});
                else
                    neg.push_back({-area, spot[k].second});
                
            }
    
            sort(pos.begin(), pos.end());
            sort(neg.begin(), neg.end());
    
            ll best = 0, sum = 0;
            ll ls = -1;
            for (pair < ll, ll > cur : pos)
            {
                sum += cur.second;
                assert(cur.first != ls);
                ls = cur.first;
                best = max(best, sum);
            }
            ls = -1;
            sum = 0;
            for (pair < ll, ll > cur : neg)
            {
                sum += cur.second;
                assert(cur.first != ls);
                ls = cur.first;
                best = max(best, sum);
            }

            //cout << "HERE " << best << endl;
            best = best + spot[i].second;
            best = best + spot[j].second;
            //cout << "new best " << best << endl;
            //ll mx = min(spot[i].second, spot[j].second);
            //cout << "mx " << mx << endl;
            if (spot[i].second < 0)
                best -= spot[i].second;
            if (spot[j].second < 0)
                best -= spot[j].second;
            //cout << "pair " << i << " " << j << " " << best << endl;
            result = max(result, best);
    
        }
    
    cout << result << endl;
}
void solve()
{
    input();
    simulate();
}
int main()
{
    solve();
    return 0;
}
/*
3
0 0 1
1 0 1
2 0 1
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 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 480 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 348 KB Output is correct
2 Correct 17 ms 496 KB Output is correct
3 Correct 18 ms 348 KB Output is correct
4 Correct 18 ms 496 KB Output is correct
5 Correct 18 ms 344 KB Output is correct
6 Correct 18 ms 348 KB Output is correct
7 Correct 18 ms 348 KB Output is correct
8 Correct 19 ms 348 KB Output is correct
9 Correct 18 ms 344 KB Output is correct
10 Correct 18 ms 348 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 1 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 1 ms 344 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 17 ms 348 KB Output is correct
22 Correct 17 ms 344 KB Output is correct
23 Correct 17 ms 348 KB Output is correct
24 Correct 16 ms 496 KB Output is correct
25 Correct 17 ms 348 KB Output is correct
26 Correct 17 ms 348 KB Output is correct
27 Correct 20 ms 604 KB Output is correct
28 Correct 17 ms 348 KB Output is correct
29 Correct 18 ms 488 KB Output is correct
30 Correct 17 ms 348 KB Output is correct
31 Correct 17 ms 348 KB Output is correct
32 Correct 17 ms 496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 348 KB Output is correct
2 Correct 17 ms 496 KB Output is correct
3 Correct 18 ms 348 KB Output is correct
4 Correct 18 ms 496 KB Output is correct
5 Correct 18 ms 344 KB Output is correct
6 Correct 18 ms 348 KB Output is correct
7 Correct 18 ms 348 KB Output is correct
8 Correct 19 ms 348 KB Output is correct
9 Correct 18 ms 344 KB Output is correct
10 Correct 18 ms 348 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 1 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 1 ms 344 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 17 ms 348 KB Output is correct
22 Correct 17 ms 344 KB Output is correct
23 Correct 17 ms 348 KB Output is correct
24 Correct 16 ms 496 KB Output is correct
25 Correct 17 ms 348 KB Output is correct
26 Correct 17 ms 348 KB Output is correct
27 Correct 20 ms 604 KB Output is correct
28 Correct 17 ms 348 KB Output is correct
29 Correct 18 ms 488 KB Output is correct
30 Correct 17 ms 348 KB Output is correct
31 Correct 17 ms 348 KB Output is correct
32 Correct 17 ms 496 KB Output is correct
33 Execution timed out 2053 ms 604 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 348 KB Output is correct
2 Correct 17 ms 496 KB Output is correct
3 Correct 18 ms 348 KB Output is correct
4 Correct 18 ms 496 KB Output is correct
5 Correct 18 ms 344 KB Output is correct
6 Correct 18 ms 348 KB Output is correct
7 Correct 18 ms 348 KB Output is correct
8 Correct 19 ms 348 KB Output is correct
9 Correct 18 ms 344 KB Output is correct
10 Correct 18 ms 348 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 1 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 1 ms 344 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 17 ms 348 KB Output is correct
22 Correct 17 ms 344 KB Output is correct
23 Correct 17 ms 348 KB Output is correct
24 Correct 16 ms 496 KB Output is correct
25 Correct 17 ms 348 KB Output is correct
26 Correct 17 ms 348 KB Output is correct
27 Correct 20 ms 604 KB Output is correct
28 Correct 17 ms 348 KB Output is correct
29 Correct 18 ms 488 KB Output is correct
30 Correct 17 ms 348 KB Output is correct
31 Correct 17 ms 348 KB Output is correct
32 Correct 17 ms 496 KB Output is correct
33 Execution timed out 2053 ms 604 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 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 480 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 18 ms 348 KB Output is correct
17 Correct 17 ms 496 KB Output is correct
18 Correct 18 ms 348 KB Output is correct
19 Correct 18 ms 496 KB Output is correct
20 Correct 18 ms 344 KB Output is correct
21 Correct 18 ms 348 KB Output is correct
22 Correct 18 ms 348 KB Output is correct
23 Correct 19 ms 348 KB Output is correct
24 Correct 18 ms 344 KB Output is correct
25 Correct 18 ms 348 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 1 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 1 ms 344 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 17 ms 348 KB Output is correct
37 Correct 17 ms 344 KB Output is correct
38 Correct 17 ms 348 KB Output is correct
39 Correct 16 ms 496 KB Output is correct
40 Correct 17 ms 348 KB Output is correct
41 Correct 17 ms 348 KB Output is correct
42 Correct 20 ms 604 KB Output is correct
43 Correct 17 ms 348 KB Output is correct
44 Correct 18 ms 488 KB Output is correct
45 Correct 17 ms 348 KB Output is correct
46 Correct 17 ms 348 KB Output is correct
47 Correct 17 ms 496 KB Output is correct
48 Execution timed out 2053 ms 604 KB Time limit exceeded
49 Halted 0 ms 0 KB -