Submission #739917

# Submission time Handle Problem Language Result Execution time Memory
739917 2023-05-11T15:24:00 Z danikoynov Measures (CEOI22_measures) C++14
59 / 100
1500 ms 6892 KB
/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|

**/

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 4e5 + 10;

int n, m;
ll d, a[maxn], b[maxn];

bool check(double x)
{
    double last = -1e18;
    for (int i = 1; i <= n; i ++)
    {
        if (last + d > a[i] + x)
            return false;
        last = max(last + d, a[i] - x);
        //cout << last << " " << a[i] << endl;
    }
    return true;
}

void solve_query()
{
    sort(a + 1, a + n + 1);
    ll lf = 0, rf = 1e18;
    //cout << check(684538602442.5) << endl;
    //exit(0);
    while(lf <= rf)
    {
        ll mf = (lf + rf) / 2;
        //cout << lf << " " << rf << endl;
        if (check(mf))
            rf = mf - 1;
        else
            lf = mf + 1;
    }

    double ans = lf;
    if (ans > 0 && check(ans - 0.5))
    {
        ans = ans - 0.5;
        printf("%0.1f ", ans);
    }
    else
    {
        cout << (ll)(round(ans)) << " ";
    }
}
void solve()
{
    cin >> n >> m >> d;
    for (int i = 1; i <= n; i ++)
        cin >> a[i];

    for (int i = 1; i <= m; i ++)
        cin >> b[i];

        bool sorted = true;
        for (int i = 2; i <= m; i ++)
        {
            if (b[i] < b[i - 1])
                sorted = false;
        }

        if (n == 0 && sorted)
        {
            cout << 0 << " ";
            double last = b[1];
            double p = 0;
            for (int i = 2; i <= m; i ++)
            {
                if (last + d > b[i] + p)
                {
                    ///cout << last << " " << b[i] <<  " " << last + d << " " << p + b[i] << endl;

                    double diff =(double)((last + d - b[i] - p)) / 2.0;
                    p = p + (double)((last + d - b[i] - p)) / 2.0;
                    last = last - diff;
                }
                last = max(last + d, b[i] - p);
                if ((ll)(floor(p)) + 0.5 == p)
                    printf("%0.1f ", p);
                else
                    cout << (ll)(p) << " ";
            }
        }
        else
        {

    for (int i = 1; i <= m; i ++)
    {
        n ++;
        a[n] = b[i];
        solve_query();
    }
        }

}

int main()
{
    ///freopen("test.txt", "r", stdin);
    solve();
    return 0;
}

/**
0 6 3
3 3 3 3 3 3
*/

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:73:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   73 |     for (int i = 1; i <= m; i ++)
      |     ^~~
Main.cpp:76:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   76 |         bool sorted = true;
      |         ^~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 212 KB Output is correct
2 Correct 4 ms 212 KB Output is correct
3 Correct 4 ms 212 KB Output is correct
4 Correct 4 ms 212 KB Output is correct
5 Correct 3 ms 212 KB Output is correct
6 Correct 4 ms 212 KB Output is correct
7 Correct 4 ms 212 KB Output is correct
8 Correct 4 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 212 KB Output is correct
2 Correct 4 ms 212 KB Output is correct
3 Correct 4 ms 212 KB Output is correct
4 Correct 4 ms 212 KB Output is correct
5 Correct 3 ms 212 KB Output is correct
6 Correct 4 ms 212 KB Output is correct
7 Correct 4 ms 212 KB Output is correct
8 Correct 4 ms 212 KB Output is correct
9 Correct 357 ms 1860 KB Output is correct
10 Correct 390 ms 1984 KB Output is correct
11 Correct 279 ms 1820 KB Output is correct
12 Correct 391 ms 1960 KB Output is correct
13 Correct 285 ms 1976 KB Output is correct
14 Correct 343 ms 1824 KB Output is correct
15 Correct 326 ms 1864 KB Output is correct
16 Correct 293 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 3020 KB Output is correct
2 Correct 142 ms 6752 KB Output is correct
3 Correct 138 ms 6684 KB Output is correct
4 Correct 94 ms 4540 KB Output is correct
5 Correct 115 ms 5932 KB Output is correct
6 Correct 118 ms 4840 KB Output is correct
7 Correct 153 ms 5876 KB Output is correct
8 Correct 114 ms 4560 KB Output is correct
9 Correct 106 ms 4608 KB Output is correct
10 Correct 141 ms 6892 KB Output is correct
11 Correct 149 ms 5324 KB Output is correct
12 Correct 140 ms 6280 KB Output is correct
13 Correct 105 ms 4476 KB Output is correct
14 Correct 116 ms 6488 KB Output is correct
15 Correct 134 ms 6268 KB Output is correct
16 Correct 90 ms 4140 KB Output is correct
17 Correct 117 ms 5880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 3020 KB Output is correct
2 Correct 142 ms 6752 KB Output is correct
3 Correct 138 ms 6684 KB Output is correct
4 Correct 94 ms 4540 KB Output is correct
5 Correct 115 ms 5932 KB Output is correct
6 Correct 118 ms 4840 KB Output is correct
7 Correct 153 ms 5876 KB Output is correct
8 Correct 114 ms 4560 KB Output is correct
9 Correct 106 ms 4608 KB Output is correct
10 Correct 141 ms 6892 KB Output is correct
11 Correct 149 ms 5324 KB Output is correct
12 Correct 140 ms 6280 KB Output is correct
13 Correct 105 ms 4476 KB Output is correct
14 Correct 116 ms 6488 KB Output is correct
15 Correct 134 ms 6268 KB Output is correct
16 Correct 90 ms 4140 KB Output is correct
17 Correct 117 ms 5880 KB Output is correct
18 Execution timed out 1572 ms 4072 KB Time limit exceeded
19 Halted 0 ms 0 KB -