Submission #340405

# Submission time Handle Problem Language Result Execution time Memory
340405 2020-12-27T14:25:32 Z mihai145 Solar Storm (NOI20_solarstorm) C++14
0 / 100
1 ms 384 KB
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

ifstream cin("txt.in");
ofstream cout("txt.out");

const int NMAX = 1e6;
const long long INF = 1e15;
const int LGMAX = 20;

int N, S;
long long K, d[NMAX + 5], v[NMAX + 5];

int lft[NMAX + 5], rgt[NMAX + 5];
int opt[NMAX + 5];
int binaryLift[NMAX + 2][LGMAX + 2];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> S >> K;

    d[0] = -INF;
    d[1] = 0;
    for(int i = 2; i <= N; i++)
    {
        cin >> d[i];
        d[i] += d[i - 1];
    }

    v[0] = 0;
    for(int i = 1; i <= N; i++)
    {
        cin >> v[i];
        v[i] += v[i - 1];
    }

    int j = 0;
    for(int i = 1; i <= N; i++)
    {
        while(j < i && d[i] - d[j] > K)
            j++;

        opt[i] = j;
        lft[i] = j - 1;
    }

    d[N + 1] = INF;
    j = N + 1;
    for(int i = N; i >= 1; i--)
    {
        while(i < j && d[j] - d[i] > K)
            j--;

        rgt[i] = j;
    }

    for(int i = N; i > 1; i--) {
        if(rgt[i] > rgt[i - 1]) {
            for(int j = rgt[i] - 1; j > rgt[i - 1]; j--)
                rgt[j] = rgt[i];
        }
    }

    for(int i = 1; i <= N; i++)
        binaryLift[rgt[i]][0] = lft[i];

    for(int step = 1; step <= LGMAX; step++)
        for(int i = 1; i <= N; i++)
            binaryLift[i][step] = binaryLift[opt[binaryLift[i][step - 1]]][step - 1];

    pair <long long, pair<int, int>> bst = {-1, {0, 0}};

    for(int rg = 1; rg <= N; rg++)
    {

        int s = S, lf = rg;

        for(int step = LGMAX; step >= 0; step--)
            if(s >= (1 << step))
            {
                lf = binaryLift[lf][step];
                s -= (1 << step);
            }

        bst = max(bst, {v[rg] - v[lf], {lf, rg}});
    }

    vector <int> sol;

    int curr = bst.second.second;
    while(curr > bst.second.first)
    {
        sol.push_back(opt[curr]);
        curr = binaryLift[opt[curr]][0];
    }

    reverse(sol.begin(), sol.end());

    cout << (int)sol.size() << '\n';
    for(auto it : sol)
        cout << it << ' ';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 376 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -