답안 #338629

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
338629 2020-12-23T14:13:17 Z kiennguyen246 Bulldozer (JOI17_bulldozer) C++14
25 / 100
2000 ms 492 KB
/**
 * \author : Nguyen Duc Kien
 * \date : 23/12/2020
 * \version : 6.3.1
 */

///Task name
#define TASK "BULLDOZER"

/**--------------------------------------------------**/

#include <bits/stdc++.h>

#define int int64_t

using namespace std;

const int maxn = 2005;
const int infi = 1e9 + 69;

int n;
struct point
{
    int x, y, w;

    void inp()
    {
        cin >> x >> y >> w;
    }
}a[maxn];
struct line
{
    long long a, b, c;

    void make_line(point A, point B)
    {
        int ux = B.x - A.x;
        int uy = B.y - A.y;
        a = -uy, b = ux;
        c = a * A.x + b * A.y;
        c = -c;
    }

    ///Raw distance (without abs)
    double pos(point A)
    {
        return double(a * A.x + b * A.y + c) / hypot(abs(a), abs(b));
    }
}d;

bool by_x(point u, point v)
{
    return (u.x < v.x);
}

bool by_pos(point u, point v)
{
    return (d.pos(u) < d.pos(v));
}

namespace Sub1
{
    long long sx[maxn], res;

    void Main()
    {
        sort(a + 1, a + n + 1, by_x);
        for (int i = 1; i <= n; i ++)
            sx[i] = sx[i - 1] + a[i].w;
        for (int i = 1; i <= n; i ++)
            for (int j = i; j <= n; j ++)
                res = max(res, sx[j] - sx[i - 1]);
        cout << res;
    }
}

namespace Sub2
{
    point b[maxn];
    int w[maxn], cnt;

    void Main()
    {
        long long res = 0;
        for (int i = 1; i <= n; i ++) res = max(res, 1ll * a[i].w);
        for (int i = 1; i <= n; i ++)
            for (int j = i + 1; j <= n; j ++)
            {
                d.make_line(a[i], a[j]);
                for (int t = 1; t <= n; t ++) b[t] = a[t];
                sort(b + 1, b + n + 1, by_pos);
//                cnt = 0;
//                memset(w, 0, sizeof(w));
//                for (int k = 1; k <= n; k ++)
//                {
//                    if (k == 1 || abs(d.pos(b[k])) != 0 || abs(d.pos(b[k - 1])) != 0) w[++cnt] = b[k].w;
//                    else w[cnt] += b[k].w;
//                }
                long long cur = 0;
                for (int k = 1; k <= n; k ++)
                {
                    cur += b[k].w;
                    res = max(res, cur);
                    if (cur < 0) cur = 0;
                }
            }
        cout << res;

    }
}

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cerr << "Processing...\n\n";
	if (fopen(TASK".INP", "r"))
	{
		freopen(TASK".INP", "r", stdin);
		freopen(TASK".OUT", "w", stdout);
	}

	cin >> n;
	for (int i = 1; i <= n; i ++) a[i].inp();
	bool all_ox = 1;
	for (int i = 1; i <= n; i ++)
        if (a[i].y != 0) all_ox = 0;
    if (all_ox) Sub1::Main();
    else Sub2::Main();
	cerr << "\n\n--------------\n";
	return 0;
}

Compilation message

bulldozer.cpp: In function 'int32_t main()':
bulldozer.cpp:119:10: 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:10: 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 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 235 ms 364 KB Output is correct
2 Correct 235 ms 492 KB Output is correct
3 Correct 240 ms 492 KB Output is correct
4 Correct 244 ms 416 KB Output is correct
5 Correct 238 ms 236 KB Output is correct
6 Correct 232 ms 364 KB Output is correct
7 Correct 241 ms 492 KB Output is correct
8 Correct 240 ms 492 KB Output is correct
9 Correct 234 ms 492 KB Output is correct
10 Correct 239 ms 492 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 240 ms 492 KB Output is correct
22 Correct 238 ms 492 KB Output is correct
23 Correct 237 ms 492 KB Output is correct
24 Correct 234 ms 492 KB Output is correct
25 Correct 234 ms 364 KB Output is correct
26 Correct 244 ms 384 KB Output is correct
27 Correct 236 ms 364 KB Output is correct
28 Correct 233 ms 364 KB Output is correct
29 Correct 240 ms 364 KB Output is correct
30 Correct 238 ms 492 KB Output is correct
31 Correct 235 ms 492 KB Output is correct
32 Correct 239 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 235 ms 364 KB Output is correct
2 Correct 235 ms 492 KB Output is correct
3 Correct 240 ms 492 KB Output is correct
4 Correct 244 ms 416 KB Output is correct
5 Correct 238 ms 236 KB Output is correct
6 Correct 232 ms 364 KB Output is correct
7 Correct 241 ms 492 KB Output is correct
8 Correct 240 ms 492 KB Output is correct
9 Correct 234 ms 492 KB Output is correct
10 Correct 239 ms 492 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 240 ms 492 KB Output is correct
22 Correct 238 ms 492 KB Output is correct
23 Correct 237 ms 492 KB Output is correct
24 Correct 234 ms 492 KB Output is correct
25 Correct 234 ms 364 KB Output is correct
26 Correct 244 ms 384 KB Output is correct
27 Correct 236 ms 364 KB Output is correct
28 Correct 233 ms 364 KB Output is correct
29 Correct 240 ms 364 KB Output is correct
30 Correct 238 ms 492 KB Output is correct
31 Correct 235 ms 492 KB Output is correct
32 Correct 239 ms 492 KB Output is correct
33 Execution timed out 2084 ms 492 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 235 ms 364 KB Output is correct
2 Correct 235 ms 492 KB Output is correct
3 Correct 240 ms 492 KB Output is correct
4 Correct 244 ms 416 KB Output is correct
5 Correct 238 ms 236 KB Output is correct
6 Correct 232 ms 364 KB Output is correct
7 Correct 241 ms 492 KB Output is correct
8 Correct 240 ms 492 KB Output is correct
9 Correct 234 ms 492 KB Output is correct
10 Correct 239 ms 492 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 240 ms 492 KB Output is correct
22 Correct 238 ms 492 KB Output is correct
23 Correct 237 ms 492 KB Output is correct
24 Correct 234 ms 492 KB Output is correct
25 Correct 234 ms 364 KB Output is correct
26 Correct 244 ms 384 KB Output is correct
27 Correct 236 ms 364 KB Output is correct
28 Correct 233 ms 364 KB Output is correct
29 Correct 240 ms 364 KB Output is correct
30 Correct 238 ms 492 KB Output is correct
31 Correct 235 ms 492 KB Output is correct
32 Correct 239 ms 492 KB Output is correct
33 Execution timed out 2084 ms 492 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 235 ms 364 KB Output is correct
17 Correct 235 ms 492 KB Output is correct
18 Correct 240 ms 492 KB Output is correct
19 Correct 244 ms 416 KB Output is correct
20 Correct 238 ms 236 KB Output is correct
21 Correct 232 ms 364 KB Output is correct
22 Correct 241 ms 492 KB Output is correct
23 Correct 240 ms 492 KB Output is correct
24 Correct 234 ms 492 KB Output is correct
25 Correct 239 ms 492 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 0 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 240 ms 492 KB Output is correct
37 Correct 238 ms 492 KB Output is correct
38 Correct 237 ms 492 KB Output is correct
39 Correct 234 ms 492 KB Output is correct
40 Correct 234 ms 364 KB Output is correct
41 Correct 244 ms 384 KB Output is correct
42 Correct 236 ms 364 KB Output is correct
43 Correct 233 ms 364 KB Output is correct
44 Correct 240 ms 364 KB Output is correct
45 Correct 238 ms 492 KB Output is correct
46 Correct 235 ms 492 KB Output is correct
47 Correct 239 ms 492 KB Output is correct
48 Execution timed out 2084 ms 492 KB Time limit exceeded
49 Halted 0 ms 0 KB -