Submission #645162

# Submission time Handle Problem Language Result Execution time Memory
645162 2022-09-26T11:29:42 Z TimDee Nicelines (RMI20_nicelines) C++17
Compilation error
0 ms 0 KB
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

//#include "nice_lines.h"
#include <bits/stdc++.h>
using namespace std;

namespace {
    const int __MAX_N = 100;

    int __subtask_id;
    int __n, __qmax, __qmin;
    int __queries;
    int __a[__MAX_N];
    int __b[__MAX_N];

    // Print score to stdout and exit.
    void score_and_exit(const double pts, const char *verdict) {
        fprintf(stderr, "Verdict = %s\n", verdict);
        fprintf(stdout, "Score = %lf\n", pts);
        exit(0);
    }

    long double compute_query(long double x, long double y) {
        long double ans; cin>>ans; return ans;
        long double l=-1e12, r=1e12, eps=1e-8;
        while (r-l>eps) {
            long double mid=(l+r)/2;
            long double y1=((mid-10*eps)*(__a[0]))+__b[0];
            long double y2=((mid)*(__a[0]))+__b[0];
            long double y3=((mid+10*eps)*(__a[0]))+__b[0];
            long double d1=sqrt((x-mid+10*eps)*(x-mid+10*eps) + (y-y1)*(y-y1));
            long double d2=sqrt((x-mid)*(x-mid) + (y-y2)*(y-y2));
            long double d3=sqrt((x-mid-10*eps)*(x-mid-10*eps) + (y-y3)*(y-y3));
            //cout<<fixed<<setprecision(12)<<l<<' '<<r<<' '<<mid<<'\n';
            //cout<<fixed<<setprecision(12)<<d1<<' '<<d2<<' '<<d3<<"\n\n";
            if (d1>=d2 && d2<=d3) break;
            if (d1<=d2 && d2<=d3) r=mid;
            else l=mid+eps;
        }
        long double X=r;
        long double Y=(r*__a[0])+__b[0];
        long double D=sqrt((x-X)*(x-X) + (y-Y)*(y-Y));
        ans=D;
        //cout<<fixed<<setprecision(12)<<x<<' '<<y<<' '<<ans<<'\n';
        return ans;
    }
    
    double score(int q) {
        if (q > __qmax) {
            return 0;
        } else if (q <= __qmin) {
            return 1;
        } else {
            return 1.0 - 0.7 * double(q - __qmin) / double(__qmax - __qmin);
        }
    }

    void wrongQueryFormat() {
        score_and_exit(0, "Invalid parameters supplied as query!");
    }

    void accepted(double pts) {
        score_and_exit(pts, "Is it OK?");
    }

    void readTest() {
        assert(scanf("%d", &__subtask_id) == 1);
        assert(scanf("%d%d%d", &__n, &__qmax, &__qmin) == 3);
        for (int i = 0; i < __n; i++) {
            assert(scanf("%d%d", &__a[i], &__b[i]) == 2);
        }
    }
}

long double query(long double x, long double y) {
    cout<<"query "<<x<<' '<<y<<'\n';
    __queries++;
    if (__queries > __qmax) {
        score_and_exit(0, "Too many queries!");
    }
    if (!isfinite(x) || !isfinite(y)
            || fabs(x) > 1e12 || fabs(y) > 1e12) {
        //fprintf(stderr, "x = %Lf, y = %Lf, ", x, y);
        cout<<fixed<<setprecision(12)<<"query "<<x<<' '<<y<<' '<<'\n';
        wrongQueryFormat();
    }
    return compute_query(x, y);
}

void the_lines_are(std::vector<int> a, std::vector<int> b) {
    assert(__n == (int)a.size() && a.size() == b.size());
    printf("Your answer is:\n");
    for (int i = 0; i < __n; i++) {
        printf("a[%d] = %d, b[%d] = %d\n", i, a[i], i, b[i]);
    }
    printf("Number of queries is: %d\n", __queries);
    accepted(score(__queries));
}

//#include "nice_lines.h"
#include <bits/stdc++.h>
using namespace std;
#define ld long double

int n;
long double fix(long double x) {
    if (fabs(x)>1e12) {
        if (x<0) return -1e12;
        else return 1e12;
    }
    return x;
}

void p1() {
    int l=-1e4, r=1e4;
    while (l<r) {
        int mid=(l+r+1)>>1;
        ld x=query(0,mid-1);
        ld y=query(0,mid);
        ld z=query(0,mid+1);
        if (x>=y && y<=z) {
            r=mid; break;
        }
        if (x<=y && y<=z) r=mid-1;
        else l=mid;
    }
    int b=r;
    l=-1e4, r=1e4;
    while (l<r) {
        int mid=(l+r+1)>>1;
        ld x=query(mid-1,0);
        ld y=query(mid,0);
        ld z=query(mid+1,0);
        if (x>=y && y<=z) {
            r=mid; break;
        }
        if (x<=y && y<=z) r=mid-1;
        else l=mid;
    }
    int a;
    if (r) a=-b/r;
    else {
        if (query(1,1)==0) a=1;
        else if (query(1,-1)==0) a=-1;
        else a=0;
    }
    the_lines_are({a},{b});
}

void p2() {

}

void solve(int id, int N) {
    n=N;

    if (n==1) {
        p1(); return;
    }

    if (n==2) {
        p2(); return;
    }

}

int main() {
    readTest();
    solve(__subtask_id, __n);
    return 0;
}

Compilation message

/usr/bin/ld: /tmp/cc1oQXvS.o: in function `query(long double, long double)':
grader.cpp:(.text+0x1a0): multiple definition of `query(long double, long double)'; /tmp/cccy1mWR.o:nicelines.cpp:(.text+0x60): first defined here
/usr/bin/ld: /tmp/cc1oQXvS.o: in function `the_lines_are(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)':
grader.cpp:(.text+0x250): multiple definition of `the_lines_are(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'; /tmp/cccy1mWR.o:nicelines.cpp:(.text+0x240): first defined here
/usr/bin/ld: /tmp/cc1oQXvS.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cccy1mWR.o:nicelines.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status