Submission #6071309


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

vector<pair<int,int>> p;
vector<set<int>> x(100001),y(100001),z;
vector<bool> vx(100001),vy(100001);


void sy(int i,set<int>& s,set<int>& t);

void sx(int i,set<int>& s,set<int>& t){
    if(vx[i]) return;
    vx[i]=1;
    for(auto& j:x[i]){
        if(s.insert(j).sd){
            sy(j,s,t);
        }
    }
}

void sy(int i,set<int>& s,set<int>& t){
    if(vy[i]) return;
    vy[i]=1;
    for(auto& j:y[i]){
        if(t.insert(j).sd){
            sx(j,s,t);
        }
    }
}

ll slvx(int i){
    if(vx[i]) return 0;
    if(x[i].size()==1) return 0;
    set<int> s,t;
    t.insert(i);
    sx(i,s,t);
    return s.size()*t.size();
}

ll slvy(int i){
    if(vy[i]) return 0;
    if(y[i].size()==1) return 0;
    set<int> s,t;
    s.insert(i);
    sy(i,s,t);
    return s.size()*t.size();
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    p.resize(n);
    for(auto& i:p){
        cin>>i.ft>>i.sd;
        x[i.ft].insert(i.sd);
        y[i.sd].insert(i.ft);
    }
    ll ans=0;
    fr(i,n){
        ans+=slvx(p[i].ft)+slvy(p[i].sd);
    }
    fr(i,n){
        ans+=!vx[p[i].ft];
    }
    cout<<ans-n<<endl;
}

Submission Info

Submission Time
Task F - Must Be Rectangular!
User Motsu_xe
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1494 Byte
Status AC
Exec Time 199 ms
Memory 29184 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 20
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 6 ms 9600 KB
02.txt AC 6 ms 9600 KB
03.txt AC 6 ms 9728 KB
04.txt AC 6 ms 9600 KB
05.txt AC 6 ms 9600 KB
06.txt AC 6 ms 9728 KB
07.txt AC 6 ms 9728 KB
08.txt AC 7 ms 9728 KB
09.txt AC 199 ms 29184 KB
10.txt AC 174 ms 24576 KB
11.txt AC 161 ms 24576 KB
12.txt AC 136 ms 20224 KB
13.txt AC 128 ms 20224 KB
14.txt AC 148 ms 24192 KB
15.txt AC 158 ms 24320 KB
16.txt AC 143 ms 24192 KB
17.txt AC 120 ms 19840 KB
s1.txt AC 6 ms 9600 KB
s2.txt AC 6 ms 9600 KB
s3.txt AC 6 ms 9728 KB