Submission #87005

#TimeUsernameProblemLanguageResultExecution timeMemory
87005Aydarov03Star triangles (IZhO11_triangle)C++14
0 / 100
2 ms376 KiB
#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)

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);
         ~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...