Submission #1371134


Source Code Expand

#include "bits/stdc++.h"
using namespace std;
#define OUT(x) cout << #x << " = " << x << endl
#define rep(i, n)             for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r)          for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r)          for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define all(x)                (x).begin(), (x).end()
#define rall(x)               (x).rbegin(), (x).rend()
template<typename T> void pv(T a, T b) { for (T i = a; i != b; i ++) cout << *i << " "; cout << endl; }
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
int in() { int x; scanf("%d", &x); return x; }
long long lin() { long long x; scanf("%lld", &x); return x; }

int V;
vector<int> g[1010101];
vector<int> rg[1010101];
vector<int> order;
bool used[1010101];
int cmp[1010101];

int n;
vector<int> x, y;

void add_edge(int from, int to) {
        g[from].push_back(to);
        rg[to].push_back(from);
}
void dfs(int v) {
        used[v] = true;
        for (auto i : g[v]) if (!used[i]) dfs(i);
        order.push_back(v);
}
void rdfs(int v, int k) {
        used[v] = true;
        cmp[v] = k;
        for (auto i : rg[v]) if (!used[i]) rdfs(i, k);
}
int StronglyConnectedComponent() {
        memset(used, 0, sizeof(used));
        order.clear();
        for (int i = 0; i < V; i ++) if (!used[i]) dfs(i);
        memset(used, 0, sizeof(used));
        int k = 0;
        for (int i = order.size() - 1; i >= 0; i --) if (!used[order[i]]) rdfs(order[i], k ++);
        return k;
}

bool B(int d) {
        rep(i, 1010101) g[i].clear();
        rep(i, 1010101) rg[i].clear();
        order.clear();
        rep(i, 1010101) used[i] = 0;
        rep(i, 1010101) cmp[i] = 0;

        int d1, d2, d3, d4;
        rep(i, n) reu(j, i + 1, n) {
                d1 = abs(x[i] - x[j]);
                d2 = abs(x[i] - y[j]);
                d3 = abs(y[i] - x[j]);
                d4 = abs(y[i] - y[j]);
                if (d1 >= d && d2 >= d && d3 >= d && d4 >= d) continue;
                else if (d1 < d && d2 < d && d3 < d && d4 < d) return false;
                else if (d1 >= d && d2 < d && d3 < d && d4 < d) {
                        add_edge(i + n, i);
                        add_edge(j + n, j);
                }
                else if (d1 < d && d2 >= d && d3 < d && d4 < d) {
                        add_edge(i + n, i);
                        add_edge(j, j + n);
                }
                else if (d1 < d && d2 < d && d3 >= d && d4 < d) {
                        add_edge(i, i + n);
                        add_edge(j + n, j);
                }
                else if (d1 < d && d2 < d && d3 < d && d4 >= d) {
                        add_edge(i, i + n);
                        add_edge(j, j + n);
                }
                else if (d1 >= d && d2 >= d && d3 < d && d4 < d) {
                        add_edge(i + n, i);
                }
                else if (d1 >= d && d2 < d && d3 >= d && d4 < d) {
                        add_edge(j + n, j);
                }
                else if (d1 >= d && d2 < d && d3 < d && d4 >= d) {
                        add_edge(i, j);
                        add_edge(i + n, j + n);
                        add_edge(j, i);
                        add_edge(j + n, i + n);
                }
                else if (d1 < d && d2 >= d && d3 >= d && d4 < d) {
                        add_edge(i, j + n);
                        add_edge(i + n, j);
                        add_edge(j + n, i);
                        add_edge(j, i + n);
                }
                else if (d1 < d && d2 >= d && d3 < d && d4 >= d) {
                        add_edge(j, j + n);
                }
                else if (d1 < d && d2 < d && d3 >= d && d4 >= d) {
                        add_edge(i, i + n);
                }
                else if (d1 >= d && d2 >= d && d3 >= d && d4 < d) {
                        add_edge(i + n, j);
                        add_edge(j + n, i);
                }
                else if (d1 >= d && d2 >= d && d3 < d && d4 >= d) {
                        add_edge(i + n, j + n);
                        add_edge(j, i);
                }
                else if (d1 >= d && d2 < d && d3 >= d && d4 >= d) {
                        add_edge(i, j);
                        add_edge(j + n, i + n);
                }
                else if (d1 < d && d2 >= d && d3 >= d && d4 >= d) {
                        add_edge(i, j + n);
                        add_edge(j, i + n);
                }
        }
        StronglyConnectedComponent();
        rep(i, n) if (cmp[i] == cmp[i + n]) return false;
        return true;
}

static const int INF = 0x3f3f3f3f;

signed main() { 
        cin >> n;
        V = 2 * n;
        x.resize(n), y.resize(n);
        rep(i, n) cin >> x[i] >> y[i];
        int l = 0, r = INF;
        while (r - l > 1) {
                int mid = (l + r) / 2;
                //cout << mid << endl;
                if (B(mid)) l = mid;
                else r = mid;
        }
        cout << l << endl;
        return 0;
}               

Submission Info

Submission Time
Task F - Flags
User KokiYmgch
Language C++14 (GCC 5.4.1)
Score 0
Code Size 5319 Byte
Status TLE
Exec Time 5315 ms
Memory 887808 KB

Compile Error

./Main.cpp: In function ‘int in()’:
./Main.cpp:12:34: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
 int in() { int x; scanf("%d", &x); return x; }
                                  ^
./Main.cpp: In function ‘long long int lin()’:
./Main.cpp:13:49: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
 long long lin() { long long x; scanf("%lld", &x); return x; }
                                                 ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1200
Status
AC × 3
AC × 25
TLE × 5
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
All 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 201 ms 52480 KB
00_example_02.txt AC 193 ms 52480 KB
00_example_03.txt AC 200 ms 52480 KB
01.txt AC 208 ms 52608 KB
02.txt AC 204 ms 52608 KB
03.txt AC 202 ms 52608 KB
04.txt AC 202 ms 52608 KB
05.txt AC 202 ms 52480 KB
06.txt AC 3019 ms 60416 KB
07.txt AC 3008 ms 60160 KB
08.txt AC 3106 ms 61952 KB
09.txt AC 214 ms 52864 KB
10.txt AC 204 ms 52608 KB
11.txt AC 202 ms 52608 KB
12.txt AC 203 ms 52608 KB
13.txt AC 198 ms 52608 KB
14.txt AC 4696 ms 75264 KB
15.txt AC 4668 ms 72704 KB
16.txt AC 4675 ms 72064 KB
17.txt AC 225 ms 53888 KB
18.txt AC 208 ms 52864 KB
19.txt TLE 5280 ms 384512 KB
20.txt TLE 5281 ms 397056 KB
21.txt AC 759 ms 65280 KB
22.txt AC 652 ms 61696 KB
23.txt AC 212 ms 54144 KB
24.txt TLE 5303 ms 771072 KB
25.txt TLE 5307 ms 819840 KB
26.txt TLE 5315 ms 887808 KB
27.txt AC 202 ms 52480 KB