結果

問題 No.3260 岩井スターグラフ
ユーザー ImzxxX
提出日時 2025-09-06 13:49:05
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 2,783 bytes
コンパイル時間 3,921 ms
コンパイル使用メモリ 275,272 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2025-09-06 13:49:31
合計ジャッジ時間 8,409 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

// 2025 9/6
// 2025 9/6

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 998244353;
template <class T>
void out(vector<vector<T>> v)
{
    for (int i = 0; i < (int)v.size(); i++)
        for (int j = 0; j < (int)v.at(i).size(); j++)
        {
            cout << v.at(i).at(j) << " ";
            if (j == (int)v.at(i).size() - 1)
                cout << endl;
        }
}
template <class T>
void out2(vector<vector<vector<T>>> v)
{
    cout << "-----------------" << endl;
    for (int i = 0; i < (int)v.size(); i++)
    {
        cout << "i:" << i << endl;
        for (int j = 0; j < (int)v.at(i).size(); j++)
            for (int k = 0; k < (int)v.at(i).at(j).size(); k++)
            {
                cout << v.at(i).at(j).at(k) << " ";
                if (k == (int)v.at(i).at(j).size() - 1)
                    cout << endl;
            }
        cout << "-----------------" << endl;
    }
}
template <class T>
void out3(vector<vector<vector<T>>> v)
{
    cout << "-----------------" << endl;
    for (int k = 0; k < (int)v.at(0).at(0).size(); k++)
    {
        cout << "k:" << k << endl;
        for (int i = 0; i < (int)v.size(); i++)
        {
            for (int j = 0; j < (int)v.at(i).size(); j++)
            {
                cout << v.at(i).at(j).at(k) << " ";
                if (j == v.at(i).size() - 1)
                    cout << endl;
            }
        }
        cout << "-----------------" << endl;
    }
}
template <class T>
bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
int power(int x, int n, int mod)
{
    int ret = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            ret *= x;

            if (mod > 0)
                ret %= mod;
        }

        x *= x;
        if (mod > 0)
            x %= mod;

        n >>= 1;
    }
    return ret;
}

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

    int x, y, n;
    cin >> x >> y >> n;

    for (int i = 0; i < n; i++)
    {
        int u, v;
        cin >> u >> v;

        if (u == 0)
        {
            int ans = v % y;
            if (ans == 0)
                ans += y;
            cout << ans << "\n";
        }
        else
        {
            if ((u - 1) / y == (v - 1) / y)
                cout << v - u << "\n";
            else
            {
                int dist1 = u % y;
                if (dist1 == 0)
                    dist1 += y;
                int dist2 = v % y;
                if (dist2 == 0)
                    dist2 += y;
                cout << dist1 + dist2 << "\n";
            }
        }
    }
}
0