Submission #958691

# Submission time Handle Problem Language Result Execution time Memory
958691 2024-04-06T11:08:16 Z Der_Vlapos IOI Fever (JOI21_fever) C++17
6 / 100
1 ms 856 KB
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #include <x86intrin.h>

#include <bits/stdc++.h>
#include <chrono>
#include <random>

// @author: Vlapos

namespace operators
{
    template <typename T1, typename T2>
    std::istream &operator>>(std::istream &in, std::pair<T1, T2> &x)
    {
        in >> x.first >> x.second;
        return in;
    }

    template <typename T1, typename T2>
    std::ostream &operator<<(std::ostream &out, std::pair<T1, T2> x)
    {
        out << x.first << " " << x.second;
        return out;
    }

    template <typename T1>
    std::istream &operator>>(std::istream &in, std::vector<T1> &x)
    {
        for (auto &i : x)
            in >> i;
        return in;
    }

    template <typename T1>
    std::ostream &operator<<(std::ostream &out, std::vector<T1> &x)
    {
        for (auto &i : x)
            out << i << " ";
        return out;
    }

    template <typename T1>
    std::ostream &operator<<(std::ostream &out, std::set<T1> &x)
    {
        for (auto &i : x)
            out << i << " ";
        return out;
    }
}

// name spaces
using namespace std;
using namespace operators;
// end of name spaces

// defines
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
#define uint unsigned int
#define all(vc) vc.begin(), vc.end()
// end of defines

// usefull stuff

void boost()
{
    ios_base ::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

inline int getbit(int &x, int &bt) { return (x >> bt) & 1; }

const int dx4[4] = {-1, 0, 0, 1};
const int dy4[4] = {0, -1, 1, 0};
const int dx8[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy8[8] = {-1, -0, 1, -1, 1, -1, 0, 1};

const ll INF = (1e18) + 500;
const int BIG = (1e9) * 2 + 100;
const int MAXN = (1e5) + 5;
const int MOD7 = (1e9) + 7;
const int MOD9 = (1e9) + 9;
const uint MODFFT = 998244353;

// #define int ll

struct test
{
    vector<vector<pii>> D1, D2, xs, ys;
    vector<pii> els;
    vector<int> d1, d2, X, Y, deleted;
    int n;

    void doArray(vector<deque<int>> &a, vector<vector<pii>> &b)
    {
        a.resize(b.size());
        for (int i = 0; i < b.size(); ++i)
            for (auto [el, bf] : b[i])
                a[i].push_back(el);
    }

    pii canBeInfected(pii curinf, int v)
    {
        if (v == -1)
            return {-1, -1};
        auto [x1, y1] = els[curinf.f];
        int dir = curinf.s;
        auto [x2, y2] = els[v];
        // const int dx4[4] = {-1, 0, 0, 1};
        // const int dy4[4] = {0, -1, 1, 0};
        if (dir == 0 and y1 >= y2)
        {
            if (x1 == x2)
                return {(y2 - y1) / 2, 3};
            else if (x1 < x2)
                return {x2 - x1, 1};
            else
                return {x1 - x2, 2};
        }
        else if (dir == 3 and y2 >= y1)
        {
            if (x1 == x2)
                return {(y2 - y1) / 2, 0};
            else if (x1 < x2)
                return {x2 - x1, 1};
            else
                return {x1 - x2, 2};
        }
        else if (dir == 1 and x2 <= x1)
        {
            if (y1 == y2)
                return {(x1 - x2) / 2, 0};
            else if (y1 < y2)
                return {y2 - y1, 0};
            else
                return {y1 - y2, 3};
        }
        else if (dir == 2 and x1 <= x2)
        {
            if (y1 == y2)
                return {(x2 - x1) / 2, 0};
            else if (y1 < y2)
                return {y2 - y1, 0};
            else
                return {y1 - y2, 3};
        }
        return {-1, -1};
    }

    int getFront(deque<int> &a)
    {
        while (a.size() and deleted[a.front()])
            a.pop_front();
        return a.size() ? a.front() : -1;
    }

    int getBack(deque<int> &a)
    {
        while (a.size() and deleted[a.back()])
            a.pop_back();
        return a.size() ? a.back() : -1;
    }

    int solve(int st, int dir)
    {
        // cout << "!!!!!!!!!!!!\n";
        deleted.assign(n, 0);
        vector<deque<int>> elsD1, elsD2, elsx, elsy;
        doArray(elsD1, D1);
        doArray(elsD2, D2);
        doArray(elsx, xs);
        doArray(elsy, ys);
        queue<pair<pii, int>> els;
        els.push({{0, dir}, 0});
        deleted[0] = 1;

        auto add = [&](int cur, pii v, int tm) -> bool
        {
            pii curtm = canBeInfected(v, cur);
            if (curtm.f >= tm)
            {
                els.push({{cur, curtm.s}, curtm.f});
                return true;
            }
            else
                return false;
        };

        auto doJob = [&](deque<int> &A, pii v, int tm) -> void
        {
            {
                int to = getFront(A);
                while (add(to, v, tm))
                {
                    // cout << v << " " << tm << " | " << to << "\n";
                    deleted[to] = 1;
                    to = getFront(A);
                }
            }
            {
                int to = getBack(A);
                while (add(to, v, tm))
                {
                    // cout << v << " " << tm << " | " << to << "\n";
                    deleted[to] = 1;
                    to = getBack(A);
                }
            }
        };

        int cnt = 0;
        while (els.size())
        {
            auto [v, tm] = els.front();
            cnt++;
            els.pop();
            doJob(elsD1[d1[v.f]], v, tm);
            doJob(elsD2[d2[v.f]], v, tm);
            doJob(elsx[X[v.f]], v, tm);
            doJob(elsy[Y[v.f]], v, tm);
        }
        return cnt;
    }

    void solve(int testcase)
    {
        boost();
        cin >> n;
        els.resize(n);
        d1.resize(n);
        d2.resize(n);
        X.resize(n);
        Y.resize(n);
        cin >> els;
        vector<int> d1vals, d2vals, xvals, yvals;
        for (auto &[x, y] : els)
        {
            x *= 2;
            y *= 2;

            d1vals.pb(x + y);
            d2vals.pb(x - y);
            xvals.pb(x);
            yvals.pb(y);
        }

        sort(all(d1vals));
        d1vals.erase(unique(all(d1vals)), d1vals.end());
        sort(all(d2vals));
        d2vals.erase(unique(all(d2vals)), d2vals.end());
        sort(all(xvals));
        xvals.erase(unique(all(xvals)), xvals.end());
        sort(all(yvals));
        yvals.erase(unique(all(yvals)), yvals.end());

        D1.resize(d1vals.size());
        D2.resize(d2vals.size());
        xs.resize(xvals.size());
        ys.resize(yvals.size());

        for (int i = 0; i < n; ++i)
        {
            auto [x, y] = els[i];
            d1[i] = lower_bound(all(d1vals), x + y) - d1vals.begin();
            d2[i] = lower_bound(all(d2vals), x - y) - d2vals.begin();
            X[i] = lower_bound(all(xvals), x) - xvals.begin();
            Y[i] = lower_bound(all(yvals), y) - yvals.begin();
            D1[d1[i]].pb({i, x});
            D2[d2[i]].pb({i, x});
            xs[X[i]].pb({i, y});
            ys[Y[i]].pb({i, x});
        }
        for (int i = 0; i < n; ++i)
        {
            if (i < D1.size())
                sort(all(D1[i]));
            if (i < D2.size())
                sort(all(D2[i]));
            if (i < xs.size())
                sort(all(xs[i]));
            if (i < ys.size())
                sort(all(ys[i]));
        }

        int res = 1;
        for (int i = 0; i < 4; ++i)
            res = max(solve(0, i), res);
        cout << res << "\n";
    }
};

main()
{
    boost();
    int q = 1;
    // cin >> q;
    for (int i = 0; i < q; i++)
    {
        test t;
        t.solve(i);
    }
    return 0;
}
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]//
//                                                                                    //
//                               Coded by Der_Vlἀpos                                  //
//                                                                                    //
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]//

Compilation message

fever.cpp: In member function 'void test::doArray(std::vector<std::deque<int> >&, std::vector<std::vector<std::pair<int, int> > >&)':
fever.cpp:105:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |         for (int i = 0; i < b.size(); ++i)
      |                         ~~^~~~~~~~~~
fever.cpp: In member function 'void test::solve(int)':
fever.cpp:283:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  283 |             if (i < D1.size())
      |                 ~~^~~~~~~~~~~
fever.cpp:285:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  285 |             if (i < D2.size())
      |                 ~~^~~~~~~~~~~
fever.cpp:287:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  287 |             if (i < xs.size())
      |                 ~~^~~~~~~~~~~
fever.cpp:289:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  289 |             if (i < ys.size())
      |                 ~~^~~~~~~~~~~
fever.cpp: At global scope:
fever.cpp:300:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  300 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 452 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Incorrect 0 ms 348 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 452 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Incorrect 0 ms 348 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 452 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Incorrect 0 ms 348 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 452 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Incorrect 0 ms 348 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 452 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Incorrect 0 ms 348 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 452 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Incorrect 0 ms 348 KB Output isn't correct
27 Halted 0 ms 0 KB -