Submission #787695

# Submission time Handle Problem Language Result Execution time Memory
787695 2023-07-19T11:01:02 Z Valters07 Measures (CEOI22_measures) C++14
24 / 100
1500 ms 3884 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long
#define en cin.close();return 0;
#define pb push_back
#define fi first//printf("%lli\n",cur);
#define se second//scanf("%lli",&n);
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll calc2(vector<int> a, int d)
{
    ll t = 0, mx = 0;
    for(int i = 1;i<a.size();i++)
    {
        t=max(0ll,t+(d-(a[i]-a[i-1])));
        mx=max(mx,t);
    }
    return mx;
}
ll calc(vector<int> a, ll d)
{
    vector<int> l, r;
    int n = a.size(), mid = n/2;
    for(int i = 0;i<n;i++)
        if(i<mid)
            l.pb(a[i]);
        else
            r.pb(a[i]);
    if(n%2)
        l.pb(a[mid]);
    reverse(l.begin(),l.end());
    for(auto &x:l)
        x=-x;
    return max(calc2(l,d),calc2(r,d))*2+(n%2==0?max(0ll,d-(a[mid]-a[mid-1])):0);
}
ll calc1(vector<int> a, int d)
{
    int n = a.size();
    for(auto &x:a)
        x*=2;
    d*=2;
    ll l = 0, r = 1e18;
    while(l<r)
    {
        ll mid = (l+r)/2;
        bool ok = 1;
        ll cur = -1e18;
        for(int i = 0;i<n;i++)
        {
            cur=max(a[i]-mid,cur+d);
            if(cur>a[i]+mid)
            {
                ok=0;
                break;
            }
        }
        if(ok)
            r=mid;
        else
            l=mid+1;
    }
    return l;
}
int main()
{
    fio
//    ifstream cin("in.in");
    int n, m, d;
    cin >> n >> m >> d;
    vector<int> a(n);
    for(auto &x:a)
        cin >> x;
    while(m--)
    {
        int x;
        cin >> x;
        a.pb(x);
        sort(a.begin(),a.end());
        ll res = calc1(a,d);
        cout << res/2;
        if(res%2)
            cout << ".5";
        cout << " ";
    }
    return 0;
}

Compilation message

Main.cpp: In function 'long long int calc2(std::vector<int>, int)':
Main.cpp:15:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for(int i = 1;i<a.size();i++)
      |                   ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 245 ms 3808 KB Output is correct
10 Correct 291 ms 3784 KB Output is correct
11 Correct 195 ms 3884 KB Output is correct
12 Correct 298 ms 3772 KB Output is correct
13 Correct 189 ms 3268 KB Output is correct
14 Correct 228 ms 3784 KB Output is correct
15 Correct 254 ms 3152 KB Output is correct
16 Correct 206 ms 3796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1586 ms 428 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1586 ms 428 KB Time limit exceeded
2 Halted 0 ms 0 KB -