結果

問題 No.3260 岩井スターグラフ
コンテスト
ユーザー nhtloc
提出日時 2025-09-18 02:49:14
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 33 ms / 2,000 ms
+ 685µs
コード長 786 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,125 ms
コンパイル使用メモリ 209,752 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-07-15 03:00:06
合計ジャッジ時間 6,147 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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