Contest Duration: - (local time) (100 minutes) Back to Home

Submission #6069906

Source Code Expand

Copy
```// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

#include <bits/stdc++.h>

using namespace std;

#define BOOST 			ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ALL(a) 			(a).begin(), (a).end()
#define SZ(a) 			(int)(a).size()
#define FOR(a, b, c) 	for (int a = (b); a <  (c); a++)
#define FORR(a, b, c) 	for (int a = (b); a >= (c); a--)
#define TRAV(a, b) 		for (auto& a : b)
#define ELO 			exit(0)
#define SORT(a)         sort(ALL(a))
#define REV(a)          reverse(ALL(a))
#define SORTR(a)        SORT(a), REV(a)
#define PB              push_back
using ll = 				long long;
using ld = 				long double; // 'long double' is 2.2 times slower than double
using pii = 			pair<int, int>;
using pll = 			pair<ll, ll>;
using vi = 				vector<int>;
using vll = 			vector<ll>;
using vpii = 			vector<pii>;
using vpll = 			vector<pll>;

template <class T> inline bool setmin(T& a, T b) {if (a > b) return a = b, 1; return 0; }
template <class T> inline bool setmax(T& a, T b) {if (a < b) return a = b, 1; return 0; }

namespace fastio {
template <class T> istream &operator>>(istream &os, vector<T> & vec){for (auto &u : vec)os >> u;return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> & vec){for (auto &u : vec)os << u << " ";return os;}
template<class T1, class T2> inline istream& operator>>(istream& os, pair<T1, T2>& p) { return os >> p.first >> p.second; }
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << p.first << " " << p.second; }
template <class T> ostream &operator<<(ostream &os, set<T> & con) { for (auto &u : con) os << u << " "; return os; }

void re() {}
template <typename T, typename... args> void re(T& x, args&... tail) { cin >> x; re(tail...); }
void pr() {}
template <typename T, typename... args> void pr(T x, args... tail) { cout << x << " "; pr(tail...);}
template <typename... args> void prln(args... tail) { pr(tail...); cout << "\n";}
}
using namespace fastio;

namespace debug {
template < typename _T > inline void _debug(const char *s, _T x) { cerr << s << " = " << x << "\n"; }
template < typename _T, typename... args > void _debug(const char *s, _T x, args... a) { while(*s != ',') cerr << *s++; cerr << " = " << x << ','; _debug(s + 1, a...); }

#if 1
#define debug(...) _debug(#__VA_ARGS__, __VA_ARGS__)
#define cerr cout
#else
#define debug(...) 1999
#define cerr if(0) cout
#endif
}
using namespace debug;

//////////////_________CODE_________//////////////

constexpr int MOD = 1e9 + 7; // 998244353
constexpr int INF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;

const int N = 1e5 + 7;
struct UF {
int tab[N], roz[N];

UF() {
FOR(i, 0, N) tab[i] = i, roz[i] = 1;
}
int Find(int a) {
return (tab[a] == a ? a : tab[a] = Find(tab[a]));
}
void Union(int a, int b) {
a = Find(a), b = Find(b);
if(a == b) return;

roz[b] += roz[a];
tab[a] = b;
}
};

UF uf;

vi id[N][2];
set<int> X[N], Y[N];

int main() {
BOOST;

int n; re(n);
vpii tab(n); re(tab);
FOR(i, 0, n) {
id[tab[i].first][0].PB(i);
id[tab[i].second][1].PB(i);
}

FOR(i, 0, N) {
FOR(j, 0, SZ(id[i][0]) - 1) {
uf.Union(id[i][0][j], id[i][0][j + 1]);
}
FOR(j, 0, SZ(id[i][1]) - 1) {
uf.Union(id[i][1][j], id[i][1][j + 1]);
}
}

FOR(i, 0, n) {
int id = uf.Find(i);
X[id].insert(tab[i].first);
Y[id].insert(tab[i].second);
}

int res = 0;

FOR(i, 0, n) {
int id = uf.Find(i);
if(id != i) continue;

if(SZ(X[id]) == 1 or SZ(Y[id]) == 1) continue;

res += SZ(X[id]) * SZ(Y[id]) - uf.roz[id];
}

prln(res);
ELO;
}```

#### Submission Info

Submission Time 2019-06-22 21:47:05+0900 F - Must Be Rectangular! DomiKo C++14 (GCC 5.4.1) 0 4082 Byte WA 103 ms 23680 KB

#### Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
 AC × 3
 AC × 16 WA × 4
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 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, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 7 ms 15104 KB
02.txt AC 7 ms 15104 KB
03.txt AC 7 ms 15104 KB
04.txt AC 7 ms 15104 KB
05.txt AC 7 ms 15104 KB
06.txt AC 7 ms 15232 KB
07.txt AC 7 ms 15232 KB
08.txt AC 7 ms 15232 KB
09.txt WA 99 ms 23680 KB
10.txt WA 98 ms 23680 KB
11.txt WA 99 ms 23680 KB
12.txt AC 95 ms 23680 KB
13.txt AC 103 ms 23680 KB
14.txt AC 98 ms 23680 KB
15.txt WA 100 ms 23680 KB
16.txt AC 98 ms 23680 KB
17.txt AC 41 ms 16896 KB
s1.txt AC 7 ms 15104 KB
s2.txt AC 7 ms 15104 KB
s3.txt AC 7 ms 15104 KB