제출 #1353951

#제출 시각아이디문제언어결과실행 시간메모리
1353951retardeIOI 바이러스 (JOI21_fever)C++20
25 / 100
5092 ms8520 KiB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

typedef long double ld;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;

const int mod = 1e9 + 7;
const ll inf = (ll)4e18;
const bool tc = false;

// NEWS
// 0123

struct pt {
    ll x, y;
    int i;
};

struct Edge {
    int to;
    int dir;
    ll w;
};

struct dj {
    ll dist;
    int i, dir;
    bool operator<(const dj &other) const {
        if (dist != other.dist) return dist < other.dist;
        if (i != other.i) return i < other.i;
        return dir < other.dir;
    }
};

const int mxn = 3005;
int n;
pt p[mxn];
vector<Edge> adj[mxn][4];

inline void solve() {
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> p[i].x >> p[i].y;
        p[i].i = i;
    }

    for (int i = 0; i < n; i++) {
        for (int d = 0; d < 4; d++) {
            adj[i][d].clear();
        }
    }
    
    for (int _1 = 0; _1 < n; _1++) {
        for (int _2 = _1 + 1; _2 < n; _2++) {
            int i = _1, j = _2;

            if (p[i].x == p[j].x) {
                // same x
                if (p[i].y > p[j].y) {
                    // i is above, so i down and j up
                    adj[i][3].pb({j, 0, p[i].y - p[j].y});
                    adj[j][0].pb({i, 3, p[i].y - p[j].y});
                } else {
                    // i is below, so i up and j down
                    adj[i][0].pb({j, 3, p[j].y - p[i].y});
                    adj[j][3].pb({i, 0, p[j].y - p[i].y});
                }
            }

            // not in line

            if (p[i].x >= p[j].x) swap(i, j);

            // i is on left

            if (llabs(p[i].x - p[j].x) != llabs(p[j].y - p[i].y)) {
                // cout << i+1 << " " << j+1 << " not comp\n";
                continue;
            }

            ll dist = llabs(p[i].x - p[j].x);
            if (p[i].y >= p[j].y) {
                // i is above
                // i goes down and j goes left
                adj[i][3].pb({j, 2, dist});
                adj[j][2].pb({i, 3, dist});
                // i goes right and j goes up
                adj[i][1].pb({j, 0, dist});
                adj[j][0].pb({i, 1, dist});
            } else {
                // i is below
                // i goes up and j goes left
                adj[i][0].pb({j, 2, dist});
                adj[j][2].pb({i, 0, dist});
                // i goes right and j goes down
                adj[i][1].pb({j, 3, dist});
                adj[j][3].pb({i, 1, dist});
            }
        }
    }

    for (int i = 0; i < n; i++) {
        for (int id = 0; id < 4; id++) {
            string s = "NEWS";
            for (auto &nxt : adj[i][id]) {
                // cout << i+1 << " in " << s[id] << " -> " << nxt.to+1 << " in " << s[nxt.dir] << " with " << nxt.w << '\n';
            }
        }
    }

    int fin = 0;
    static ll dist[mxn][4];

    for (int sd = 0; sd < 4; sd++) {
        set<dj> dijk;
        dijk.insert({0, 0, sd});
        int ans = 0;

        fill(&dist[0][0], &dist[0][0] + mxn * 4, inf);
        dist[0][sd] = 0;

        string s = "NEWS\n";

        while (!dijk.empty()) {
            dj curr = *dijk.begin();
            dijk.erase(dijk.begin());
            ans++;
            ll curdist = curr.dist;

            // cout << "Seeing " << curr.i+1 << " in " << s[curr.dir] << '\n';
            // cout << "Currdist " << curdist << '\n';

            for (auto &nxt : adj[curr.i][curr.dir]) {
                int j = nxt.to;
                int jd = nxt.dir;
                ll edge = nxt.w;

                // cout << "Neighbour " << j+1 << " in " << s[jd] << " will reach at " << edge << '\n';
                if (curdist > edge) {
                    // cout << "Too late\n";
                    continue;
                }
                if (edge > dist[j][jd]) {
                    // cout << "Useless\n";
                    continue;
                }

                if (dist[j][jd] != inf) {
                    dijk.erase({dist[j][jd], j, jd});
                }
                dist[j][jd] = edge;
                dijk.insert({dist[j][jd], j, jd});
            }
        }

        fin = max(fin, ans);
    }

    cout << fin << '\n';
}

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

signed main() {
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    //setIO();

    int t = 1;
    if (tc) {
        cin >> t;
    }

    while (t--) {
        solve();
    }
}

컴파일 시 표준 에러 (stderr) 메시지

fever.cpp: In function 'void setIO(std::string)':
fever.cpp:185:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  185 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fever.cpp:186:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  186 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…