Submission #158741

#TimeUsernameProblemLanguageResultExecution timeMemory
158741vanicSIR (COI15_sir)C++14
100 / 100
223 ms20064 KiB
#include <cstdio> #include <vector> #include <algorithm> using namespace std; typedef long long ll; const int maxn=3e5+5; pair < ll, ll > l[maxn]; pair < ll, ll > svi[maxn]; vector < pair < ll, ll > > bitne; vector < pair < ll, ll > > ost; ll hull(pair < ll, ll > a, pair < ll, ll > b, pair < ll, ll > c){ return a.first*(b.second-c.second)+b.first*(c.second-a.second)+c.first*(a.second-b.second); } int main(){ int n; scanf("%d", &n); for(int i=0; i<n; i++){ scanf("%lld%lld", &l[i].first, &l[i].second); } int m; scanf("%d", &m); for(int i=0; i<m; i++){ scanf("%lld%lld", &svi[i].first, &svi[i].second); } sort(svi, svi+m); for(int i=0; i<m; i++){ while(bitne.size()>1 && hull(bitne[bitne.size()-2], bitne.back(), svi[i])<=0){ bitne.pop_back(); } bitne.push_back(svi[i]); } for(int i=m-1; i>-1; i--){ while(ost.size()>1 && hull(ost[ost.size()-2], ost.back(), svi[i])<=0){ ost.pop_back(); } ost.push_back(svi[i]); } for(int i=1; i<ost.size()-1; i++){ bitne.push_back(ost[i]); } int sz=bitne.size(); /* printf("%d\n", sz); for(int i=0; i<sz; i++){ printf("%lld %lld\n", bitne[i].first, bitne[i].second); }*/ int pos1=0, pos2=0; ll mini=1e10; for(int i=0; i<sz; i++){ if(mini>abs(l[0].first-bitne[i].first)+abs(l[0].second-bitne[i].second)){ mini=abs(l[0].first-bitne[i].first)+abs(l[0].second-bitne[i].second); pos1=i; } } ll sum=0; ll maksi=0; int pos3; for(int i=0; i<n; i++){ while(hull(l[i], bitne[(pos1+1)%sz], bitne[pos1])>0){ pos1=(pos1+1)%sz; } while(hull(l[i], l[(pos2+1)%n], bitne[pos1])>0){ sum+=hull(l[i], l[pos2], l[(pos2+1)%n]); pos2=(pos2+1)%n; } pos3=(i+1)%n; maksi=max(maksi, sum); sum-=hull(l[i], l[pos3], l[pos2]); } printf("%lld\n", maksi); return 0; }

Compilation message (stderr)

sir.cpp: In function 'int main()':
sir.cpp:43:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1; i<ost.size()-1; i++){
               ~^~~~~~~~~~~~~
sir.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
sir.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &l[i].first, &l[i].second);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sir.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &m);
  ~~~~~^~~~~~~~~~
sir.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &svi[i].first, &svi[i].second);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...