제출 #1341197

#제출 시각아이디문제언어결과실행 시간메모리
1341197ezzzaySquirrel (RMI18_squirrel)C++20
0 / 100
2222 ms49456 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

static constexpr int LIM = 20010;
static bitset<LIM> cop[LIM];

ll ans = 0;

void build_coprime_table() {
    cop[1][0] = 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 (i - j > j) cop[i][j] = cop[i - j][j];
            else cop[i][j] = cop[j][i - j];
        }
    }
}

inline bool visible(int x, int y) {
    if (x < y) swap(x, y);
    while (y && (x >= LIM || y >= LIM)) {
        int nx = y;
        int ny = x % y;
        x = nx;
        y = ny;
    }
    if (!y) return x == 1;
    return cop[x][y];
}

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

    if ((dx == 0 || dy == 0) && 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_coprime_table();
    int M, N, F;
    cin >> M >> N >> F;
    while (F--) {
        int x, y, k;
        cin >> x >> y >> k;  
        ans += visible(x, y);    
        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...