Submission #1340991

#TimeUsernameProblemLanguageResultExecution timeMemory
1340991stoneSquirrel (RMI18_squirrel)C++20
0 / 100
4800 ms233504 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

static const int LIM = 50010;
static bitset<LIM> cop[LIM];

ll ans = 0;

void build() {
    cop[1][0] = 1;
    cop[1][1] = 1;
    for (int i = 1; i < LIM; ++i) {
        for (int j = 0; j <= i; ++j) {
            if (i == 1 && j <= 1) continue;
            if (j == 0) {
                cop[i][j] = (i == 1);
            } else if (i - j > j) {
                cop[i][j] = cop[i - j][j];
            } else {
                cop[i][j] = cop[j][i - j];
            }
        }
    }
}

inline bool visible(ll x, ll y) {
    x = llabs(x);
    y = llabs(y);
    if (x < y) swap(x, y);
    return cop[x][y];
}

void dfs(ll x, ll y, ll k, ll dx, ll dy) {
    for (ll i = 0; i < k; ++i) {
        x += dx;
        y += dy;
        if (visible(x, y)) ans++;
    }

    if (k == 1) return;

    if (dx == 0) {
        dfs(x, y, k >> 1, -1, dy);
        dfs(x, y, k >> 1,  1, dy);
    } else if (dy == 0) {
        dfs(x, y, k >> 1, dx, -1);
        dfs(x, y, k >> 1, dx,  1);
    } else {
        dfs(x, y, k, dx, 0);
        dfs(x, y, k, 0, dy);
    }
}

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

    build();

    int M, N, F;
    cin >> M >> N >> F;

    while (F--) {
        ll x, y, k;
        cin >> x >> y >> k;

        --x;
        --y;

        if (visible(x, y)) ans++;
        dfs(x, y, k, -1, 0);
    }

    cout << ans << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...