Submission #1005279

# Submission time Handle Problem Language Result Execution time Memory
1005279 2024-06-22T09:40:39 Z Valaki2 Nuclearia (CEOI15_nuclearia) C++14
30 / 100
1000 ms 280656 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

struct plant {
    int x, y, a, b;
};

void printans(int total, int area) {
    int gcd = __gcd(total, area);
    total /= gcd;
    area /= gcd;
    if(area == 2) {
        cout << total / 2 + 1 << "\n";
        return;
    }
    cout << total / area + ((total % area <= area / 2) ? 0 : 1) << "\n";
}

int w, h;
int n;
int q;

vector<vector<int> > rad;
vector<vector<int> > pref;
vector<plant> plants;

void solve() {
    cin >> w >> h;
    rad.assign(1 + w, vector<int> (1 + h, 0));
    pref.assign(1 + w, vector<int> (1 + h, 0));
    cin >> n;
    plants.resize(n);
    for(int i = 0; i < n; i++) {
        cin >> plants[i].x >> plants[i].y >> plants[i].a >> plants[i].b;
    }
    for(plant p : plants) {
        for(int i = 1; i <= w; i++) {
            for(int j = 1; j <= h; j++) {
                rad[i][j] += max(0ll, p.a - p.b * max(abs(i - p.x), abs(j - p.y)));
            }
        }
    }
    for(int i = 1; i <= w; i++) {
        for(int j = 1; j <= h; j++) {
            pref[i][j] = rad[i][j] + pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1];
        }
    }
    cin >> q;
    for(int i = 0; i < q; i++) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        int total = pref[x2][y2] - pref[x2][y1 - 1] - pref[x1 - 1][y2] + pref[x1 - 1][y1 - 1];
        int area = (y2 - y1 + 1) * (x2 - x1 + 1);
        printans(total, area);
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 438 ms 274292 KB Output is correct
2 Correct 58 ms 4540 KB Output is correct
3 Correct 37 ms 3920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 406 ms 274256 KB Output is correct
2 Correct 47 ms 4688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 156 ms 39972 KB Output is correct
2 Correct 46 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 151 ms 42376 KB Output is correct
2 Correct 43 ms 4580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 343 ms 276560 KB Output is correct
2 Correct 50 ms 5460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 428 ms 112212 KB Output is correct
2 Correct 53 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 220 ms 42052 KB Output is correct
2 Correct 48 ms 5200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 307 ms 57424 KB Output is correct
2 Correct 45 ms 4432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1042 ms 280608 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1057 ms 280656 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1048 ms 46172 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1074 ms 45916 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1066 ms 46780 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1066 ms 46172 KB Time limit exceeded
2 Halted 0 ms 0 KB -