結果

問題 No.3260 岩井スターグラフ
ユーザー shinji_mm
提出日時 2025-09-07 12:40:03
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 362 ms / 2,000 ms
コード長 743 bytes
コンパイル時間 2,850 ms
コンパイル使用メモリ 276,152 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2025-09-07 12:40:19
合計ジャッジ時間 14,295 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define FOR(i,a,b) for(ll i = a; i < (ll)(b); i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using VI = vector<int>;
using P = pair<int,int>;
const long long INF = 1LL << 60;
const int DX[] = {1,0,-1,0};
const int DY[] = {0,1,0,-1};

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	
	ll x,y,n;
	cin >> x >> y >> n;
	rep(i,n){
		ll u,v;
		cin >> u >> v;
		
		if(u == 0 || v == 0){
			if(u == 0){
				cout << (v-1)%y+1 << endl;
			}
			else{
				cout << (u-1)%y+1 << endl;
			}
		}
		else if((u-1)/y == (v-1)/y){
			cout << abs(u-v) << endl;
		}
		else{
			cout << (u-1)%y+1 + (v-1)%y+1 << endl;
		}
	}
	return 0;
}
0