Submission #1333507

#TimeUsernameProblemLanguageResultExecution timeMemory
1333507mfmme23Nicelines (RMI20_nicelines)C++20
0 / 100
52 ms480 KiB
#include "nice_lines.h"
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

typedef long double ld;


const ld X_VAL = 20000.0; 
const ld EPS = 1e-9;

ld get_slope(ld y) {
    ld delta = 1e-7;
    ld f1 = query(X_VAL, y - delta);
    ld f2 = query(X_VAL, y + delta);
    return (f2 - f1) / (2.0 * delta);
}

void find_roots(ld y_low, ld y_high, ld s_low, ld s_high, vector<ld>& roots) {
  
    if (abs(s_high - s_low) < EPS) return;

    if (y_high - y_low < 1e-4) {
        roots.push_back((y_low + y_high) / 2.0);
        return;
    }

    ld y_mid = (y_low + y_high) / 2.0;
    ld s_mid = get_slope(y_mid);

    find_roots(y_low, y_mid, s_low, s_mid, roots);
    find_roots(y_mid, y_high, s_mid, s_high, roots);
}

void solve(int subtask_id, int N) {
    
    ld Y_LIMIT = 20000.0 * 10000.0 + 20000.0;
    
    vector<ld> roots;
    ld s_low = get_slope(-Y_LIMIT);
    ld s_high = get_slope(Y_LIMIT);
    
    find_roots(-Y_LIMIT, Y_LIMIT, s_low, s_high, roots);

    vector<int> va, vb;
    for (ld r : roots) {
        
        int a = (int)round(r / X_VAL);
        int b = (int)round(r - (ld)a * X_VAL);
        va.push_back(a);
        vb.push_back(b);
    }

   
    the_lines_are(va, vb);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...