Submission #25768664


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool cust(pair<ll,ll>&x,pair<ll,ll>&y){
    if(x.first!=y.first)return x.first<y.first;
    else return x.second<y.second;
}
ll power(long long x, ll y, ll p)
{
    ll res = 1;     
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; 
        x = (x*x) % p;
    }
    return res;
}
void dfs(int x,vector<set<int>>&adj,vector<pair<int,int>>&c,int par){
    for(auto j:adj[x]){
        if(j!=par){
            c[j].first=x;
            dfs(j,adj,c,x);
        }
    }
}
int find(vector<pair<int,int>>&par,int i){
    if(par[i].first!=i)return par[i].first=find(par,par[i].first);
    return par[i].first;
}
int merge(vector<pair<int,int>>&par,int i,int j){
    if(par[i].second>par[j].second){
        par[j].first=i;
    }
    else if(par[i].second<par[j].second){
        par[i].first=j;
    }
    else{
        par[j].first=i;
        par[i].second++;
    }
}
// ll f[200005];
// ll modInverse(ll x, ll m){
// 	return power(x, m-2, m);
// }
// ll ncr(ll n,ll r, ll p)
// {
//     if (n < r)
//         return 0;
    
//     if (r == 0)
//         return 1;

 
//     return (f[n] * modInverse(f[r], p) % p * modInverse(f[n - r], p) % p)% p;
// }
void convert(vector<string>&s){
    for(int i=0;i<s.size();i++){
	        int f=0;
	        for(int j=0;j<s[i].size();j++){
	            if(s[i][j]=='#'){
	                f=1;
	                break;
	            }
	        }
	        if(f==1)break;
	        else {
	            s.erase(s.begin()+i);
	            i--;
	        }
	    }
	    for(int i=s.size()-1;i>=0;i--){
	        int f=0;
	        for(int j=0;j<s[i].size();j++){
	            if(s[i][j]=='#'){
	                f=1;
	                break;
	            }
	        }
	        if(f==1)break;
	        else {
	            s.erase(s.begin()+i);
	        }
	    }
	    for(int i=0;i<s[0].size();i++){
	        int f=0;
	        for(int j=0;j<s.size();j++){
	            if(s[j][i]=='#'){
	                f=1;
	                break;
	            }
	        }
	        if(f)break;
	        else{
	           for(int j=0;j<s.size();j++){
    	            s[j].erase(s[j].begin()+i);
    	        }
    	        i--;
	        }
	    }
	    for(int i=s[0].size()-1;i>=0;i--){
	        int f=0;
	        for(int j=0;j<s.size();j++){
	            if(s[j][i]=='#'){
	                f=1;
	                break;
	            }
	        }
	        if(f)break;
	        else{
	           for(int j=0;j<s.size();j++){
    	            s[j].erase(s[j].begin()+i);
    	        }
	        }
	    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t=1;
	//cin>>t;
	//cout<<add(9,2021)<<endl;
	
	while(t--){
	   int n;
	   cin>>n;
	   vector<pair<int,int>>arr(n);
	   set<pair<int,int>>s;
	   for(int i=0;i<n;i++){
	       cin>>arr[i].first>>arr[i].second;
	       s.insert({arr[i].first,arr[i].second});
	   }
	   int ans=0;
	   for(int i=0;i<n;i++){
	       for(int j=i+1;j<n;j++){
	           if(arr[i].first==arr[j].first||arr[i].second==arr[j].second)continue;
	           if(s.find({arr[i].first,arr[j].second})!=s.end()&&s.find({arr[j].first,arr[i].second})!=s.end())ans++;
	       }
	   }
	   cout<<ans/2<<endl;
	}
	return 0;
}

Submission Info

Submission Time
Task D - Rectangles
User prateek3110
Language C++ (GCC 9.2.1)
Score 400
Code Size 3462 Byte
Status AC
Exec Time 210 ms
Memory 3772 KiB

Compile Error

./Main.cpp: In function ‘int merge(std::vector<std::pair<int, int> >&, int, int)’:
./Main.cpp:45:1: warning: no return statement in function returning non-void [-Wreturn-type]
   45 | }
      | ^
./Main.cpp: In function ‘void convert(std::vector<std::__cxx11::basic_string<char> >&)’:
./Main.cpp:62:18: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::__cxx11::basic_string<char> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   62 |     for(int i=0;i<s.size();i++){
      |                 ~^~~~~~~~~
./Main.cpp:64:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   64 |          for(int j=0;j<s[i].size();j++){
      |                      ~^~~~~~~~~~~~
./Main.cpp:78:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   78 |          for(int j=0;j<s[i].size();j++){
      |                      ~^~~~~~~~~~~~
./Main.cpp:89:19: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   89 |      for(int i=0;i<s[0].size();i++){
      |                  ~^~~~~~~~~~~~
./Main.cpp:91:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::__cxx11::basic_string<char> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   91 |          for(int j=0;j<s.size();j++){
      |                      ~^~~~~~~~~
./Main.cpp:99:26: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::__cxx11::basic_string<char> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   99 |             for(int j=0;j<s.size();j++){
      |                         ~^~~~~~~~~
./Main.cp...

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 29
Set Name Test Cases
Sample sample_00.txt, sample_01.txt, sample_02.txt
All case_00.txt, case_01.txt, case_02.txt, case_03.txt, case_04.txt, case_05.txt, case_06.txt, case_07.txt, case_08.txt, case_09.txt, case_10.txt, case_11.txt, case_12.txt, case_13.txt, case_14.txt, case_15.txt, case_16.txt, case_17.txt, case_18.txt, case_19.txt, case_20.txt, case_21.txt, case_22.txt, case_23.txt, case_24.txt, case_25.txt, sample_00.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
case_00.txt AC 210 ms 3772 KiB
case_01.txt AC 209 ms 3664 KiB
case_02.txt AC 210 ms 3716 KiB
case_03.txt AC 208 ms 3688 KiB
case_04.txt AC 203 ms 3668 KiB
case_05.txt AC 204 ms 3728 KiB
case_06.txt AC 207 ms 3564 KiB
case_07.txt AC 204 ms 3608 KiB
case_08.txt AC 205 ms 3756 KiB
case_09.txt AC 206 ms 3628 KiB
case_10.txt AC 198 ms 3632 KiB
case_11.txt AC 203 ms 3760 KiB
case_12.txt AC 205 ms 3724 KiB
case_13.txt AC 204 ms 3716 KiB
case_14.txt AC 206 ms 3564 KiB
case_15.txt AC 42 ms 3760 KiB
case_16.txt AC 72 ms 3556 KiB
case_17.txt AC 70 ms 3720 KiB
case_18.txt AC 66 ms 3708 KiB
case_19.txt AC 72 ms 3720 KiB
case_20.txt AC 73 ms 3616 KiB
case_21.txt AC 69 ms 3720 KiB
case_22.txt AC 67 ms 3608 KiB
case_23.txt AC 69 ms 3608 KiB
case_24.txt AC 67 ms 3620 KiB
case_25.txt AC 67 ms 3720 KiB
sample_00.txt AC 2 ms 3660 KiB
sample_01.txt AC 3 ms 3504 KiB
sample_02.txt AC 3 ms 3572 KiB