提出 #36129413


ソースコード 拡げる

#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for (ll i=a;i<(ll)n;i++)
ll read(){ll r;scanf("%lld",&r);return r;}
template<class T>
using Point = std::pair<T, T>;

template<class T>
class ConvexHull{
public:
  std::vector<Point<T>> lower;
  std::vector<Point<T>> upper;
  Point<T> sub(const Point<T>&a,const Point<T>&b)const{ // return a-b
    return {a.first-b.first,a.second-b.second};
  }
  T cross(const Point<T>& a,const Point<T>& b,const Point<T>& c)const{ // (a-b) x (c-b)
    auto [x0,y0] = sub(a,b);
    auto [x1,y1] = sub(c,b);
    return x1*y0 -x0*y1;
  }
  ConvexHull(std::vector<Point<T>>&p) {
    sort(p.begin(),p.end());
    {
      std::vector<Point<T>> v=p; // 逆时针弧
      for(Point<T>p : v){
        while(lower.size() >= 2 && cross(lower.rbegin()[1], lower.back(), p) <= 0) lower.pop_back();
        lower.push_back(p);
      }
    }
    {
      std::vector<Point<T>> v=p; // 顺时针弧
      for(Point<T>p : v){
        while(upper.size() >= 2 && cross(upper.rbegin()[1], upper.back(), p) >= 0) upper.pop_back();
        upper.push_back(p);
      }
    }
  }
  T cxy(const std::vector<Point<T>>&v) const{
    T ret=20;
    rep(i,1,v.size()){
      auto [x0,y0]=v[i-1];
      auto [x1,y1]=v[i];
      auto dx=x1-x0;
      auto dy=y1-y0;
      if(std::abs(dx-dy)<0.001)continue; // 分母为0 平行y=x
      auto xy = (y0*dx-x0*dy)/(dx-dy);
      if((x0-xy)*(x1-xy) < 0) ret=std::min(ret,xy); // 在两点之间
    }
    return 1/ret;
  }
  T cut()const {
    return std::max(cxy(lower),cxy(upper));
  }
};

int main(){
  int n=read();
  std::vector<Point<double>>points;
  double ans=0;
  rep(i,0,n){
    ll a=read(); // [1e8,1e9]
    ll b=read();
    ll c=read();
    ans=std::max(ans,c*1.0/std::max(a,b));
    points.push_back(std::pair{a*1.0/c,b*1.0/c}); // [0.1,10]
  }
  ConvexHull<double> ch(points);
  if(n==1){
    printf("%.15lf\n",ans);
    return 0;
  }
  ans=std::max(ans,ch.cut());
  printf("%.15lf\n",ans);
  return 0;
}

提出情報

提出日時
問題 G - Infinite Knapsack
ユーザ cromarmot
言語 C++ (GCC 9.2.1)
得点 600
コード長 1985 Byte
結果 AC
実行時間 98 ms
メモリ 9508 KiB

コンパイルエラー

./Main.cpp: In function ‘ll read()’:
./Main.cpp:4:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
    4 | ll read(){ll r;scanf("%lld",&r);return r;}
      |                ~~~~~^~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 2
AC × 30
セット名 テストケース
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt, 02_handmade_07.txt, 02_handmade_08.txt, 02_handmade_09.txt, 03_hack_01.txt
ケース名 結果 実行時間 メモリ
00_sample_01.txt AC 7 ms 3576 KiB
00_sample_02.txt AC 2 ms 3660 KiB
01_test_01.txt AC 79 ms 9436 KiB
01_test_02.txt AC 81 ms 9232 KiB
01_test_03.txt AC 95 ms 9336 KiB
01_test_04.txt AC 94 ms 9504 KiB
01_test_05.txt AC 93 ms 9392 KiB
01_test_06.txt AC 97 ms 9388 KiB
01_test_07.txt AC 94 ms 9344 KiB
01_test_08.txt AC 92 ms 9508 KiB
01_test_09.txt AC 94 ms 9344 KiB
01_test_10.txt AC 93 ms 9296 KiB
01_test_11.txt AC 94 ms 9244 KiB
01_test_12.txt AC 94 ms 9376 KiB
01_test_13.txt AC 94 ms 9392 KiB
01_test_14.txt AC 93 ms 9392 KiB
01_test_15.txt AC 94 ms 9388 KiB
01_test_16.txt AC 93 ms 9504 KiB
01_test_17.txt AC 93 ms 9336 KiB
01_test_18.txt AC 93 ms 9504 KiB
02_handmade_01.txt AC 2 ms 3700 KiB
02_handmade_02.txt AC 94 ms 9348 KiB
02_handmade_03.txt AC 94 ms 9236 KiB
02_handmade_04.txt AC 94 ms 9348 KiB
02_handmade_05.txt AC 94 ms 9388 KiB
02_handmade_06.txt AC 79 ms 9392 KiB
02_handmade_07.txt AC 79 ms 9504 KiB
02_handmade_08.txt AC 98 ms 9436 KiB
02_handmade_09.txt AC 93 ms 9376 KiB
03_hack_01.txt AC 43 ms 8608 KiB