제출 #322340

#제출 시각아이디문제언어결과실행 시간메모리
322340saarang123Solar Storm (NOI20_solarstorm)C++14
0 / 100
242 ms262144 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

signed main() {
    std::ios::sync_with_stdio(0);
    std::cout.tie(0);
    std::cin.tie(0);
    int n, s, k;
    cin >> n >> s >> k;
    vector<ll> a(n + 1), d(n + 1);
    vector<array<ll, 2>> c(n + 1);
    vector<vector<int>> dp(n + 1, vector<int>(s + 1));
    for(int i = 1; i < n; i++) cin >> d[i];
    for(int i = 1; i <= n; i++) cin >> a[i], a[i] += a[i - 1]; //prefix sums
    vector<ll> p(n + 1);
    for(int i = 1; i <= n; i++) p[i] = p[i - 1] + d[i - 1];
    //cout << "prefix sums: ";
    //for(int i = 1; i <= n; i++) cout << p[i] << ' '; cout << '\n';
    for(int i = 1; i <= n; i++) {
        int id = lower_bound(p.begin(), p.end(), p[i] + k) - p.begin();
        if(id > n || p[id] > p[i] + k) id--;
        //cout << id << ' ';
        c[i][0] += a[id] - a[i];
        c[i][1] = id + 1;
        id = lower_bound(p.begin(), p.end(), p[i] - k) - p.begin();
        c[i][0] += a[i] - a[id];
        if(id) c[i][0] += a[id] - a[id - 1];
        //cout << id << ' ' << c[i][0] << '\n';
    }
    for(int i = 1; i <= s; i++) dp[n][i] = a[n] - a[n - 1];
    for(int i = n - 1; i; i--) {
        for(int j = s; j; j--) {
            int nxt = c[i][1];
            dp[i][j] = c[i][0] + dp[nxt][j - 1];
        }
    }
    //cout << "dp:\n";
    //for(int i = 1; i <= n; i++) { for(int j = 0; j <= s; j++) cout << dp[i][j] << ' '; cout << '\n';}
    ll ans = 0;
    array<int, 2> best;
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j <= s; j++) {
            if(ans < dp[i][j]) ans = dp[i][j], best = {i, j};
        }
    }
    vector<int> shield;
    function<void(int i, int j)> out = [&] (int i, int j) {
        if(j == 0) return;
        shield.push_back(i);
        out(c[i][1], j - 1);
    };
    out(best[0], best[1]);
    //cout << ans << '\n';
    cout << shield.size() << '\n';
    for(int x : shield) cout << x << ' '; cout << '\n';
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

SolarStorm.cpp: In function 'int main()':
SolarStorm.cpp:56:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   56 |     for(int x : shield) cout << x << ' '; cout << '\n';
      |     ^~~
SolarStorm.cpp:56:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   56 |     for(int x : shield) cout << x << ' '; cout << '\n';
      |                                           ^~~~
SolarStorm.cpp:41:19: warning: 'best.std::array<int, 2>::_M_elems[0]' may be used uninitialized in this function [-Wmaybe-uninitialized]
   41 |     array<int, 2> best;
      |                   ^~~~
SolarStorm.cpp:41:19: warning: 'best.std::array<int, 2>::_M_elems[1]' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...