Submission #84871

# Submission time Handle Problem Language Result Execution time Memory
84871 2018-11-17T16:12:02 Z nikolapesic2802 Lightning Conductor (POI11_pio) C++14
36 / 100
552 ms 23212 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
struct func{
    int poz;
    int h;
};
double f(func x,int i)
{
    double sol=x.h+(double)sqrt((double)abs(i-x.poz));
    return sol;
}
int N;
struct liChao{
    vector<func> tr;
    void init(func start)
    {
        tr.resize(4*N);
        fill(tr.begin(),tr.end(),start);
    }
    void set(func x,int i=1,int l=0,int r=N)
    {
        int m=(l+r)>>1;
        bool lft=f(x,l)>f(tr[i],l);
        bool mid=f(x,m)>f(tr[i],m);
        if(mid){
            swap(tr[i],x);
        }
        if(r-l==1)
            return;
        if(lft!=mid)
        {
            set(x,2*i,l,m);
        }
        else
        {
            set(x,2*i+1,m,r);
        }
    }
    double get(int poz,int i=1,int l=0,int r=N)
    {
        int m=(l+r)>>1;
        if(r-l==1)
            return f(tr[i],poz);
        if(poz<m)
            return max(f(tr[i],poz),get(poz,2*i,l,m));
        else
            return max(f(tr[i],poz),get(poz,2*i+1,m,r));
    }
} ST;
int main()
{
    int n;
    scanf("%i",&n);
    N=n;
    vector<int> h(n);
    for(int i=0;i<n;i++)
    {
        scanf("%i",&h[i]);
        func tr;
        tr.h=h[i];
        tr.poz=i;
        if(i==0)
            ST.init(tr);
        else
            ST.set(tr);
    }
    for(int i=0;i<n;i++)
    {
        double d=ST.get(i);
        int a=d;
        if(d>a)
            a++;
        assert(a>=h[i]);
        printf("%i\n",a-h[i]);
    }
    return 0;
}

Compilation message

pio.cpp: In function 'int main()':
pio.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i",&n);
     ~~~~~^~~~~~~~~
pio.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i",&h[i]);
         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 1724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 2676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 3080 KB Output is correct
2 Correct 60 ms 3080 KB Output is correct
3 Incorrect 62 ms 3224 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 98 ms 4372 KB Output is correct
2 Correct 100 ms 4412 KB Output is correct
3 Incorrect 98 ms 4948 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 239 ms 9684 KB Output is correct
2 Correct 241 ms 9684 KB Output is correct
3 Incorrect 247 ms 10224 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 407 ms 16368 KB Output is correct
2 Correct 377 ms 16368 KB Output is correct
3 Incorrect 369 ms 16368 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 552 ms 23004 KB Output is correct
2 Correct 531 ms 23004 KB Output is correct
3 Incorrect 534 ms 23180 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 546 ms 23180 KB Output is correct
2 Correct 541 ms 23180 KB Output is correct
3 Incorrect 536 ms 23212 KB Output isn't correct