Submission #273323

# Submission time Handle Problem Language Result Execution time Memory
273323 2020-08-19T04:51:50 Z lookcook Divide and conquer (IZhO14_divide) C++17
17 / 100
3 ms 2688 KB
#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';
}

Compilation message

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 time Memory Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Correct 3 ms 2688 KB Output is correct
3 Correct 3 ms 2688 KB Output is correct
4 Correct 3 ms 2688 KB Output is correct
5 Correct 3 ms 2688 KB Output is correct
6 Correct 3 ms 2688 KB Output is correct
7 Correct 3 ms 2688 KB Output is correct
8 Correct 3 ms 2688 KB Output is correct
9 Correct 3 ms 2688 KB Output is correct
10 Correct 3 ms 2688 KB Output is correct
11 Correct 3 ms 2688 KB Output is correct
12 Correct 3 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Correct 3 ms 2688 KB Output is correct
3 Correct 3 ms 2688 KB Output is correct
4 Correct 3 ms 2688 KB Output is correct
5 Correct 3 ms 2688 KB Output is correct
6 Correct 3 ms 2688 KB Output is correct
7 Correct 3 ms 2688 KB Output is correct
8 Correct 3 ms 2688 KB Output is correct
9 Correct 3 ms 2688 KB Output is correct
10 Correct 3 ms 2688 KB Output is correct
11 Correct 3 ms 2688 KB Output is correct
12 Correct 3 ms 2688 KB Output is correct
13 Correct 3 ms 2688 KB Output is correct
14 Correct 3 ms 2688 KB Output is correct
15 Incorrect 3 ms 2688 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Correct 3 ms 2688 KB Output is correct
3 Correct 3 ms 2688 KB Output is correct
4 Correct 3 ms 2688 KB Output is correct
5 Correct 3 ms 2688 KB Output is correct
6 Correct 3 ms 2688 KB Output is correct
7 Correct 3 ms 2688 KB Output is correct
8 Correct 3 ms 2688 KB Output is correct
9 Correct 3 ms 2688 KB Output is correct
10 Correct 3 ms 2688 KB Output is correct
11 Correct 3 ms 2688 KB Output is correct
12 Correct 3 ms 2688 KB Output is correct
13 Correct 3 ms 2688 KB Output is correct
14 Correct 3 ms 2688 KB Output is correct
15 Incorrect 3 ms 2688 KB Output isn't correct
16 Halted 0 ms 0 KB -