# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
87009 | Aydarov03 | Star triangles (IZhO11_triangle) | C++14 | 2 ms | 536 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
vector <int> x , y;
vector < pair<int,int> > xy;
int l( vector<int> a , int cnt)
{
int l = 0 , r = a.size() - 1;
while( r - l > 1 )
{
int mid = l + (r - l) / 2;
if( a[mid] >= cnt)
r = mid;
else
l = mid;
}
if(a[l] == cnt)return l;
else if(a[r] == cnt)return r;
else return -1;
}
int u(vector<int> a , int cnt)
{
int l = 1 , r = a.size() - 1;
while( r - l > 1 )
{
int mid = r - (r - l) / 2;
if( a[mid] <= cnt)
l = mid;
else
r = mid;
}
if(a[r] == cnt)return r;
else if(a[l] == cnt)return l;
else return -1;
}
main()
{
// freopen("triangles.in" , "r" , stdin);
// freopen("triangles.out" , "w" , stdout);
int n , ans = 0;
cin >> n;
for(int i = 1; i <= n; i++)
{
int a , b;
scanf("%d%d" , &a , &b);
x.push_back(a);
y.push_back(b);
xy.push_back( {a , b} );
}
sort( xy.begin() , xy.end() );
sort( x.begin() , x.end() );
sort( y.begin() , y.end() );
for(int i = 0; i < xy.size(); i++)
{
ans += min( (u(x,xy[i].first)-l(x,xy[i].first)) , (u(y,xy[i].second)-l(y,xy[i].second)));
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |