제출 #1283859

#제출 시각아이디문제언어결과실행 시간메모리
1283859cheskaSolar Storm (NOI20_solarstorm)C++20
0 / 100
109 ms121832 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define ppii pair<int, pii> 
#define tiii tuple<int, int, int>
#define g0 get<0>
#define g1 get<1>
#define g2 get<2>
#define f first
#define pb push_back
const int N = 1e6+5;
const int S = 50;
const int MOD = 1e9+7;
int ans[N][2], point[N][S];
signed main() {
    freopen("in.in", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, s, k; cin >> n >> s >> k;
    vector<int> a(n);
    for (int i = 1; i < n; i++) {
        int j; cin >> j; a[i]=a[i-1]+j;
    }
    vector<int> v(n), psv(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    psv[0] = v[0];
    for (int i = 1; i < n; i++) {
        psv[i] = psv[i-1]+v[i];
    }
    for (int i = n-1; i >= 0; i--) {
        for (int j = 1; j <= s; j++) {
            int r = upper_bound(a.begin(), a.end(), a[i]+k)-a.begin();
            int l = lower_bound(a.begin(), a.end(), a[i]-k)-a.begin();
            if (j != 1) point[i][j] = r;
            else point[i][j] = n;
            if (r == n) {
                if (l == 0) ans[i][j%2] = psv[n-1];
                else ans[i][j%2] = psv[n-1]-psv[l-1];
            }
            else {
                if (l == 0) ans[i][j%2] = ans[r][(j+1)%2];
                else ans[i][j%2] = ans[r][(j+1)%2]+psv[r-1]-psv[l-1];
            }
        }
    }
    int ans2 = 0;
    for (int i = 0; i < n; i++) {
        if (ans[ans2][s%2] < ans[i][s%2]) ans2 = i;
    }
    vector<int> fin;
    while (ans2 != n) {
        fin.pb(ans2);
        ans2 = point[ans2][s];
        s--;
    }
    cout << fin.size() << '\n';
    for (int i : fin) cout << i+1 << " ";
}

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

SolarStorm.cpp: In function 'int main()':
SolarStorm.cpp:17:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     freopen("in.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#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...