Submission #439080

# Submission time Handle Problem Language Result Execution time Memory
439080 2021-06-29T07:37:54 Z Hausdorf Solar Storm (NOI20_solarstorm) C++17
15 / 100
1247 ms 233528 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define itn int
#define fi first
#define se second
#pragma optimization ("O3")
#pragma GCC target ("avx2")
#pragma optimization ("unroll_loops")
int maxn = 1e6 + 50;
vector<vector<ll>> go(maxn, vector<ll> (21));
vector<int> d(maxn), v(maxn);
vector<ll> presum(maxn), h(maxn);
bool isdeeper (int a, int b) { // true if a is deeper
    return h[a] >= h[b];
}
int binlift (int a, int k) {
    for (int l = 20; l >= 0; --l) {
        if (k & (1 << l)) {
            a = go[a][l];
        }
    }
    return a;
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, s; ll k; cin >> n >> s >> k;
    for (int i = 1; i < n; ++i)
        cin >> d[i];
    for (int i = 1; i <= n; ++i)
        cin >> v[i];
    presum[0] = 0;
    h[1] = 0;
    for (int i = 1; i <= n; ++i)
        presum[i] = presum[i - 1] + v[i];
    for (int i = 2; i <= n; ++i) {
        h[i] = h[i - 1] + d[i - 1];
        //cout << h[i] << ' ';
    } //cout << endl;
    go[n][0] = n + 1;
    go[n + 1][0] = n + 1;
    for (int i = 1; i < n; ++i) {
        int j = (int) (upper_bound(h.begin() + 1, h.begin() + n + 1, h[i] + k) - h.begin() - 1);
        //cout << i << ' ' << j << endl;
        j = (int) (upper_bound(h.begin() + 1, h.begin() + n + 1, h[j] + k) - h.begin() - 1);
        //cout << i << ' ' << j << endl;
        go[i][0] = j + 1;
    }
    for (int l = 1; l <= 20; ++l) {
        for (int i = 1; i <= n + 1; ++i) {
            go[i][l] = go[go[i][l - 1]][l - 1];
        }
    }
    ll ans = -1;
    for (int i = 1; i < n; ++i) {
        ans = max(ans, presum[binlift(i, s) - 1] - presum[i - 1]);
    }
    //cout << ans << endl;
    for (int i = 1; i < n; ++i) {
        if (ans == presum[binlift(i, s) - 1] - presum[i - 1]) {
            vector<int> shields;
            for (int j = i; j < n && shields.size() < s; j = go[j][0]) {
                shields.push_back((int) (upper_bound(h.begin() + 1, h.begin() + n + 1, h[j] + k) - h.begin() - 1));
            }
            cout << shields.size() << '\n';
            for (int elem : shields)
                cout << elem << ' ';
            break;
        }
    }
}

Compilation message

SolarStorm.cpp:8: warning: ignoring '#pragma optimization ' [-Wunknown-pragmas]
    8 | #pragma optimization ("O3")
      | 
SolarStorm.cpp:10: warning: ignoring '#pragma optimization ' [-Wunknown-pragmas]
   10 | #pragma optimization ("unroll_loops")
      | 
SolarStorm.cpp: In function 'int main()':
SolarStorm.cpp:64:53: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   64 |             for (int j = i; j < n && shields.size() < s; j = go[j][0]) {
      |                                      ~~~~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 201 ms 219464 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 701 ms 226840 KB Output is correct
2 Correct 502 ms 224224 KB Output is correct
3 Correct 577 ms 224580 KB Output is correct
4 Correct 654 ms 224996 KB Output is correct
5 Correct 710 ms 225988 KB Output is correct
6 Correct 869 ms 227656 KB Output is correct
7 Correct 632 ms 225216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 201 ms 219464 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 888 ms 233384 KB Output is correct
2 Correct 642 ms 224224 KB Output is correct
3 Correct 616 ms 224220 KB Output is correct
4 Correct 764 ms 226336 KB Output is correct
5 Correct 740 ms 226132 KB Output is correct
6 Correct 747 ms 226524 KB Output is correct
7 Correct 1247 ms 233528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 201 ms 219464 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 201 ms 219464 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 201 ms 219464 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -