제출 #1307508

#제출 시각아이디문제언어결과실행 시간메모리
1307508naman123Snowball (JOI21_ho_t2)C++20
0 / 100
2603 ms218384 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, q;
    cin >> n >> q;

    vector<long long> pos(n);
    for (int i = 0; i < n; i++) cin >> pos[i];

    vector<long long> w(q);
    for (int i = 0; i < q; i++) cin >> w[i];

    vector<long long> weight(n, 0);

    // snow[x] = true means interval [x, x+1) still has snow
    map<long long, bool> snow;

    for (int day = 0; day < q; day++) {
        for (int i = 0; i < n; i++) {
            long long from = pos[i];
            long long to = pos[i] + w[day];

            if (from < to) {
                // moving east
                for (long long x = from; x < to; x++) {
                    if (!snow.count(x)) snow[x] = true;
                    if (snow[x]) {
                        weight[i]++;
                        snow[x] = false;
                    }
                }
            } else {
                // moving west
                for (long long x = from - 1; x >= to; x--) {
                    if (!snow.count(x)) snow[x] = true;
                    if (snow[x]) {
                        weight[i]++;
                        snow[x] = false;
                    }
                }
            }

            pos[i] = to;
        }
    }

    for (int i = 0; i < n; i++) {
        cout << weight[i] << '\n';
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...