結果

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

ソースコード

diff #

#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;

using ll = long long;
using ld = long double;

//using mint = modint; //mint::set_mod(M);
//using mint = modint998244353;
//using mint = modint1000000007;

template<class T> using pq = priority_queue<T>; //大きい順
template<class T> using pq_g = priority_queue<T, vector<T>, greater<T>>; //小さい順

#define vec_unique(v) v.erase(unique(v.begin(), v.end()), v.end()) //重複削除
#define vec_iota(v) iota(v.begin(), v.end(), 0) //0, 1, 2, 3, ..., n - 1にセット
#define concat(a, b) a.insert(a.end(), b.begin(), b.end())
#define debug(x) cerr << #x << " = " << x << endl

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
//int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

#define INF 2e18
#define INF2 2e9

int main() {
    int x, y, n;
    cin >> x >> y >> n;
    for(int i = 0; i < n; i++) {
        ll u, v;
        cin >> u >> v;
        if(u == 0 || v == 0) {
            if(u != 0) u = (u - 1) % y;
            if(v != 0) v = (v - 1) % y;
            cout << abs(u - v) + 1 << endl; 
            continue;  
        }
        if((u - 1) / y == (v - 1) / y) {
            cout << abs(u - v) << endl;
            continue;
        }
        u = (u - 1) % y;
        v = (v - 1) % y;
        cout << (u + 1 + v + 1) << endl;
    }
    //cout << fixed << setprecision(15) << << endl;
    return 0;
}
0