QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#136526 | #6401. Classic: N Real DNA Pots | ammardab3an# | WA | 1ms | 3856kb | C++20 | 3.7kb | 2023-08-09 00:05:42 | 2023-08-09 00:05:46 |
Judging History
answer
// By AmmarDab3an
#include "bits/stdc++.h"
using namespace std;
#define int int64_t
#define ll int64_t
// typedef unsigned int uint;
// typedef long long int ll;
// typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> iii;
typedef pair<ll, pll> lll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define endl '\n'
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define freopenI freopen("input.txt", "r", stdin);
#define freopenO freopen("output.txt", "w", stdout);
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int x, int y) {
return uniform_int_distribution<int>(x, y)(rng);
}
int mul(int a, int b){
int ret = (1ll * (a%MOD) * (b%MOD)) % MOD;
return (ret+MOD)%MOD;
}
int add(int a, int b){
int ret = (1ll * (a%MOD) + (b%MOD)) % MOD;
return (ret+MOD)%MOD;
}
int pow_exp(int n, int p){
if(!p) return 1;
if(p&1) return mul(n, pow_exp(n, p-1));
int tmp = pow_exp(n, p/2);
return mul(tmp, tmp);
}
int inv(int x){
return pow_exp(x, MOD-2);
}
const int MAX = 2e5 + 10;
const int NMAX = 2e5 + 10;
const int MMAX = 2e5 + 10;
const int LOG_MAX = ceil(log2(double(NMAX)));
const int BLOCK = ceil(sqrt(double(NMAX)));
int fac[NMAX], ifac[NMAX];
void init(){
fac[0] = 1;
for(int i = 1; i < NMAX; i++){
fac[i] = mul(fac[i-1], i);
}
ifac[NMAX-1] = inv(fac[NMAX-1]);
for(int i = NMAX-2; i >= 0; i--){
ifac[i] = mul(ifac[i+1], i+1);
}
}
int choose(int n, int c){
assert(n >= c);
return mul(fac[n], mul(ifac[c], ifac[n-c]));
}
typedef long double dt;
struct segTree{
vi tree;
segTree(int n){
tree = vi(n*4);
}
void update(int nd, int l, int r, int p, int v){
if(p < l || r < p){
return;
}
if(l==r){
tree[nd] = max(tree[nd], v);
return;
}
int mid = (l+r)/2;
update(nd*2, l, mid, p, v);
update(nd*2+1, mid+1, r, p, v);
tree[nd] = max(tree[nd*2], tree[nd*2+1]);
}
int query(int nd, int l, int r, int q_l, int q_r){
if(r < q_l || q_r < l){
return 0;
}
if(q_l <= l && r <= q_r){
return tree[nd];
}
int mid = (l+r)/2;
int st_path = query(nd*2, l, mid, q_l, q_r);
int nd_path = query(nd*2+1, mid+1, r, q_l, q_r);
return max(st_path, nd_path);
}
};
int32_t main(){
fastIO;
#ifdef LOCAL
freopenI;
freopenO;
#endif
// freopen("name.in", "r", stdin);
// init();
int n, k;
cin >> n >> k;
vpii vec(n);
for(auto &[x, y] : vec) cin >> x >> y;
auto check = [&](dt m){
vi tmp(n);
for(int i = 0; i < n; i++){
auto [x, y] = vec[i];
dt v = dt(y)-m*dt(x);
tmp[i] = int(v * dt(1e9));
}
vi ttmp = tmp;
sort(ttmp.begin(), ttmp.end());
ttmp.erase(unique(ttmp.begin(), ttmp.end()), ttmp.end());
for(auto &e : tmp){
e = lower_bound(ttmp.begin(), ttmp.end(), e) - ttmp.begin();
}
int sz = ttmp.size();
segTree st(sz);
for(int i = 0; i < n; i++){
int v = tmp[i];
int cans = st.query(1, 0, sz-1, 0, v) + 1;
st.update(1, 0, sz-1, v, cans);
}
return st.query(1, 0, sz-1, 0, sz-1);
};
dt l = -1e10;
dt r = 1e10;
dt ans = -1;
int cnt = 200;
while(cnt--){
dt mid = l + (r-l)/2.0;
if(check(mid) >= k){
ans = mid;
l = mid;
}
else{
r = mid;
}
}
cout << fixed << setprecision(10) << ans << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3808kb
input:
4 3 1 2 2 4 3 3 4 1
output:
-0.9999999997
result:
ok found '-1.0000000', expected '-1.0000000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3856kb
input:
2 2 1 1 5 3
output:
0.5000000002
result:
ok found '0.5000000', expected '0.5000000', error '0.0000000'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3744kb
input:
2 2 222640995 547139825 489207317 725361095
output:
10000000000.0000000000
result:
wrong answer 1st numbers differ - expected: '0.6685813', found: '10000000000.0000000', error = '9999999999.3314190'