제출 #273323

#제출 시각아이디문제언어결과실행 시간메모리
273323lookcookDivide and conquer (IZhO14_divide)C++17
17 / 100
3 ms2688 KiB
#include <bits/stdc++.h>

#define int long long

using namespace std;

const int maxn = 100005;
int psa[3][maxn]; // 0 = x, 1 = gold, 2 = energy

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    for (int i = 0; i < 3; i++) for (int j = 0; j < maxn; j++) psa[i][j] = 0;
    int n;
    cin >> n;
    int last = 0;
    int xs[n+1], gs[n+1], ds[n+1];
    for (int i = 1; i <= n; i++) {
        int x, g, d;
        cin >> x >> g >> d;
        xs[i] = x;
        gs[i] = g;
        ds[i] = d;
        int tmp = x;
        x -= last;
        last = tmp;
        psa[0][i] += x;
        psa[1][i] += g;
        psa[2][i] += d;
    }
    for (int i = 0; i < 3; i++) for (int j = 1; j < maxn; j++) psa[i][j] += psa[i][j-1];
    int best = 0;
    for (int l = 1; l <= n; l++) {
        int pos = l;
        for (int i = 17; i >= 0; i--) {
            if (pos+(1<<i) < maxn && psa[0][pos+(1<<i)]-psa[0][l]  <= psa[2][pos+(1<<i)]-psa[2][l-1]) {
                pos += (1<<i);
            }
        }
        int gold = psa[1][pos]-psa[1][l-1];
        best = max(best, gold);
    }
    cout << best << '\n';
}

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

divide.cpp: In function 'int main()':
divide.cpp:17:9: warning: variable 'xs' set but not used [-Wunused-but-set-variable]
   17 |     int xs[n+1], gs[n+1], ds[n+1];
      |         ^~
divide.cpp:17:18: warning: variable 'gs' set but not used [-Wunused-but-set-variable]
   17 |     int xs[n+1], gs[n+1], ds[n+1];
      |                  ^~
divide.cpp:17:27: warning: variable 'ds' set but not used [-Wunused-but-set-variable]
   17 |     int xs[n+1], gs[n+1], ds[n+1];
      |                           ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...