답안 #87005

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
87005 2018-11-29T06:43:23 Z Aydarov03 별들과 삼각형 (IZhO11_triangle) C++14
0 / 100
2 ms 376 KB
#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

triangle.cpp:46:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
triangle.cpp: In function 'int main()':
triangle.cpp:69:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < xy.size(); i++)
                    ~~^~~~~~~~~~~
triangle.cpp:48:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("triangles.in" , "r" , stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
triangle.cpp:49:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("triangles.out" , "w" , stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
triangle.cpp:58:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d" , &a , &b);
         ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -