Submission #1326236

#TimeUsernameProblemLanguageResultExecution timeMemory
1326236adscodingBulldozer (JOI17_bulldozer)C++20
5 / 100
17 ms440 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define FOR(i, a, b) for (int i = a, _b = b; i <= _b; ++i)
#define FORD(i, a, b) for (int i = a, _b = b; i >= _b; --i)
#define FORLL(i, a, b) for (ll i = a, _b = b; i <= _b; ++i)
#define FORDLL(i, a, b) for (ll i = a, _b = b; i >= _b; --i)
#define all(x) x.begin(), x.end()
#define uni(x) sort(all(x)), x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__)

template<typename T>
void __prine_one(const char *&s, const T &x)
{
    while (*s == ' ') ++s;
    const char *p = s;
    int bal = 0;
    while (*s)
    {
        if (*s == '(') ++bal;
        else if (*s == ')') --bal;
        else if (*s == ',' && bal == 0) break;
        ++s;
    }
    cerr.write(p, s - p) << " = " << x;
    if (*s == ',')
    {
        cerr << "  ,  ";
        ++s;
    }
}

template<typename... Args>
void debug(const char *s, Args... args)
{
    cerr << "[  ";
    int dummy[] = {0, (__prine_one(s, args), 0)...};
    (void)dummy;
    cerr << "  ]\n\n";
}

template<class X>
bool maximize(X &a, const X &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

template<class X>
bool minimize(X &a, const X &b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

// --------------------------------------------------------------------------------------------

const int maxn = 2005;
int n;

struct Geo
{
    ll x, y, val;
    Geo() {}
    Geo(ll x, ll y) : x(x), y(y) {}
};

struct Line
{
    ll a, b, c;
    Line() {}
    Line(ll a, ll b, ll c) : a(a), b(b), c(c) {}
    Line(Geo A, Geo B)
    {
        a = A.y - B.y;
        b = B.x - A.x;
        c = -a * A.x - b * A.y;
    }

    ll eval(ll x, ll y)
    {
        return a * x + b * y + c;
    }
};

Geo a[maxn];

// --------------------------------------------------------------------------------------------


namespace sub1
{
    bool c1 = true, c2 = true;
    bool approve()
    {
        FOR(i, 2, n)
        {
            c1 &= a[i].x == a[i - 1].x;
            c2 &= a[i].y == a[i - 1].y;
        }
        return c1 || c2;
    }

    void solve()
    {
        cerr << "SUB1: \n\n";
        if (c2)
            sort(a + 1, a + n + 1, [&](const Geo &A, const Geo &B) {
                return A.x < B.x;
            });
        else
            sort(a + 1, a + n + 1, [&](const Geo &A, const Geo &B) {
                return A.y < B.y;
            });

        ll res = 0, cur = 0;
        FOR(i, 1, n)
        {
            cur = max(0ll, cur + a[i].val);
            res = max(res, cur);
        }

        cout << res;
    }
}

namespace sub2
{
    bool approve()
    {
        return true;
    }

    void solve()
    {
        cerr << "SUB2: \n\n";
        ll res = 0;
        FOR(i, 1, n)
            res = max(res, a[i].val);

        FOR(i, 1, n)
            FOR(j, i + 1, n)
            {
                Line L(a[i], a[j]);
                vector<pll> vec[2];
                
                FOR(k, 1, n)
                {
                    if (k == i || k == j) continue;
                    ll cur = L.eval(a[k].x, a[k].y);
                    vec[cur > 0 ? 1 : 0].push_back({abs(cur), k});
                }
                FOR(k, 0, 1)
                {
                    sort(all(vec[k]));
                    ll cur = a[i].val + a[j].val;
                    res = max(res, cur);
                     for (const auto &p : vec[k])
                    {
                        cur += a[p.se].val;
                        res = max(res, cur);
                    }
                }

                // dbg(i, j, res);
            }

        cout << res;
    }
}


void solve()
{
    cin >> n;
    FOR(i, 1, n)
        cin >> a[i].x >> a[i].y >> a[i].val;
    if (sub1 :: approve()) return sub1 :: solve(), void();
    sub2 :: solve();
}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #define TASK "TEST"
    if (fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        freopen(TASK".OUT", "w", stdout);
    }
    solve();
    return 0;
}

Compilation message (stderr)

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:202:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  202 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bulldozer.cpp:203:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  203 |         freopen(TASK".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...