제출 #399451

#제출 시각아이디문제언어결과실행 시간메모리
399451534351IOI 바이러스 (JOI21_fever)C++17
25 / 100
5072 ms2828 KiB
#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)

const int MAXN = 1e5 + 13;
const int INF = 1e9 + 7;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

int N;
pll arr[MAXN];
int dir[MAXN];
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
bitset<MAXN> flag;
int ans = 1;

int testdir(int d)
{
    // cerr << "TEST " << d << endl;
    int res = 1, curt = 0;
    FOR(i, 0, N)
    {
        flag[i] = false;
        dir[i] = -1;
    }
    flag[0] = true;
    dir[0] = d;
    while(true)
    {
        int guy = -1, guydir = -1, guyt = INF;
        FOR(i, 0, N)
        {
            if (flag[i]) continue;
            FOR(j, 0, N)
            {
                if (!flag[j]) continue;
                // if (abs(arr[i].fi - arr[j].fi) != abs(arr[i].se - arr[j].se)) continue;
                int t = (abs(arr[i].fi - arr[j].fi) + abs(arr[i].se - arr[j].se)) / 2;
                if (t < curt) continue;
                FOR(k, 0, 4)
                {
                    if (arr[j].fi + t * dx[dir[j]] == arr[i].fi + t * dx[k] && arr[j].se + t * dy[dir[j]] == arr[i].se + t * dy[k] && t < guyt)
                    {
                        guyt = t;
                        guydir = k;
                        guy = i;
                    }
                }
            }
        }
        if (guy == -1) break;
        // cerr << "infect " << guy << ' ' << guyt << endl;
        flag[guy] = true;
        dir[guy] = guydir;
        curt = guyt;
        res++;
    }
    return res;
}

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(4);
    cin >> N;
    FOR(i, 0, N)
    {
        cin >> arr[i].fi >> arr[i].se;
        arr[i].fi *= 2; arr[i].se *= 2;
    }
    FOR(i, 0, 4)
    {
        ckmax(ans, testdir(i));
    }
    cout << ans << '\n';
    return 0;
}
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...