結果

問題 No.3260 岩井スターグラフ
ユーザー nhtloc
提出日時 2025-09-18 02:49:14
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 786 bytes
コンパイル時間 1,731 ms
コンパイル使用メモリ 195,000 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-09-18 02:49:23
合計ジャッジ時間 9,240 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using int64 = long long;

// Hàm tính nhánh và độ sâu
pair<int64,int64> get_branch_depth(int64 v, int64 Y) {
    if (v == 0) return {-1, 0};              // đỉnh trung tâm
    return {(v - 1) / Y, (v - 1) % Y + 1};   // {nhánh, độ sâu}
}

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

    int64 X, Y;
    int N;
    cin >> X >> Y >> N;

    while (N--) {
        int64 u, v;
        cin >> u >> v;
        auto [bu, du] = get_branch_depth(u, Y);
        auto [bv, dv] = get_branch_depth(v, Y);

        int64 ans;
        if (bu == bv) ans = llabs(du - dv);   // cùng nhánh
        else          ans = du + dv;          // khác nhánh → qua 0

        cout << ans << "\n";
    }
    return 0;
}
0