結果
問題 |
No.3260 岩井スターグラフ
|
ユーザー |
![]() |
提出日時 | 2025-09-06 13:19:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 76 ms / 2,000 ms |
コード長 | 7,412 bytes |
コンパイル時間 | 4,979 ms |
コンパイル使用メモリ | 259,336 KB |
実行使用メモリ | 8,064 KB |
最終ジャッジ日時 | 2025-09-06 13:19:55 |
合計ジャッジ時間 | 9,839 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 |
ソースコード
#ifndef INCLUDED_MAIN #define INCLUDED_MAIN #include __FILE__ // このファイル自体をインクルード void solve() { ll X, Y, N; cin >> X >> Y >> N; vector<ll> U(N), V(N); REP(i, N) { cin >> U[i] >> V[i]; // U[i]--; // V[i]--; } VI ans(N); REP(i, N) { if (U[i] == 0) { ans[i] = (V[i] - 1) % Y + 1; continue; } ll a = (U[i] - 1) / Y; ll b = (V[i] - 1) / Y; if (a == b) { ans[i] = abs(U[i] - V[i]); continue; } ans[i] = (U[i] - 1) % Y + 1 + (V[i] - 1) % Y + 1; } pv(ans, true); } signed main() { solve(); return 0; } #else // INCLUDED_MAIN using namespace std; #include <bits/stdc++.h> #include <atcoder/all> using namespace atcoder; #define CPP_STR(x) CPP_STR_I(x) #define CPP_CAT(x, y) CPP_CAT_I(x, y) #define CPP_STR_I(args...) #args #define CPP_CAT_I(x, y) x##y #define ASSERT(expr...) assert((expr)) using i8 = int8_t; using u8 = uint8_t; using i16 = int16_t; using u16 = uint16_t; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; using f32 = float; using f64 = double; // }}} constexpr i64 INF = 1'010'000'000'000'000'017LL; constexpr int inf = 1073741823; constexpr i64 MOD = 998244353LL; constexpr f64 EPS = 1e-12; constexpr f64 PI = 3.14159265358979323846; #define M5 100007 #define M9 1000000000 #define F first #define S second // util {{{ #define FOR(i, start, end) for (i64 i = (start), CPP_CAT(i, xxxx_end) = (end); i < CPP_CAT(i, xxxx_end); ++i) #define RFOR(i, start, end) for (ll i = start - 1; i >= end; i--) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, n, 0) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define ll long long int #define VI vector<ll> #define VVI vector<VI> #define VC vector<char> #define VVC vector<VC> #define VS vector<string> #define VVS vector<VS> #define VB vector<bool> #define VVB vector<VB> #define VM vector<mint> #define VVM vector<VM> #define vec vector #define pb push_back #define ISD true #define debug(x) \ if (ISD) \ cout << #x << ": " << x << endl #define DEBUG(x) cout << #x << ": " << x << endl template <typename C> i64 SIZE(const C &c) { return static_cast<i64>(c.size()); } template <typename T, size_t N> i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); } template <typename T, typename U, typename Comp = less<>> bool chmax(T &xmax, const U &x, Comp comp = {}) { if (comp(xmax, x)) { xmax = x; return true; } return false; } template <typename T, typename U, typename Comp = less<>> bool chmin(T &xmin, const U &x, Comp comp = {}) { if (comp(x, xmin)) { xmin = x; return true; } return false; } // }}} // init {{{ struct ProconInit { static constexpr int IOS_PREC = 15; static constexpr bool AUTOFLUSH = false; ProconInit() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(IOS_PREC); if (AUTOFLUSH) cout << unitbuf; } } PROCON_INIT; // }}} //-------------------------------------------------------------------- bool isKaibun(string st) { int n = st.length(); REP(i, n / 2) { if (st[i] != st[n - i - 1]) { return false; } } return true; } int toInt(char a) { return a - '0'; } ll gcd(ll a, ll b) { if (a % b == 0) { return (b); } else { return (gcd(b, a % b)); } } vector<long long> enum_divisors(long long N) { vector<long long> res; for (long long i = 1; i * i <= N; ++i) { if (N % i == 0) { res.push_back(i); // 重複しないならば i の相方である N/i も push if (N / i != i) res.push_back(N / i); } } // 小さい順に並び替える sort(res.begin(), res.end()); return res; } vector<pair<long long, long long>> prime_factorize(long long N) { vector<pair<long long, long long>> res; for (long long a = 2; a * a <= N; ++a) { if (N % a != 0) continue; long long ex = 0; // 指数 // 割れる限り割り続ける while (N % a == 0) { ++ex; N /= a; } // その結果を push res.push_back({a, ex}); } // 最後に残った数について if (N != 1) res.push_back({N, 1}); return res; } long long GCD(long long a, long long b) { if (b == 0) return a; else return GCD(b, a % b); } ll lcm(ll a, ll b) { return a * b / GCD(a, b); } long long safe_pow(long long a, long long b) { long long res = 1; for (long long i = 0; i < b; i++) { double dres = res; dres *= a; if (dres > 2e18) { return 2e18; } res *= a; } return res; } long long sqrt_floor(long long x) { long long l = 0, r = 2e9; while (l <= r) { long long t = (l + r) / 2; if (t * t > x) { r = t - 1; } else { l = t + 1; } } return r; } ll popcount(ll bit) { ll c = 0; while (bit > 0) { c += bit % 2; bit /= 2; } return c; } bool on(ll N, ll K) { return N & (1LL << K); } template <typename T1, typename T2> std::ostream &operator<<(std::ostream &os, std::pair<T1, T2> p) { os << "{" << p.first << "," << p.second << "}"; return os; } bool outof(ll y, ll x, ll h, ll w) { return y < 0 || x < 0 || y >= h || x >= w; }; // 配列の要素を空白区切りで出力 第二引数をtrueにすると改行区切り template <typename T> inline void pv(const vector<T> &v, bool split_line = false) { if (v.empty()) { cout << "This vector is empty." << endl; return; } const bool isValue = is_integral<T>::value; for (int i = 0; i < (int)v.size(); i++) { if (isValue) { if ((v[i] == inf) || (v[i] == INF)) cout << 'x' << " \n"[split_line || i + 1 == (int)v.size()]; else cout << v[i] << " \n"[split_line || i + 1 == (int)v.size()]; } else cout << v[i] << " \n"[split_line || i + 1 == (int)v.size()]; } } template <typename T1, typename T2> inline void pv(const vector<pair<T1, T2>> &v, bool split_line = false) { if (v.empty()) { cout << "This vector is empty." << endl; return; } for (int i = 0; i < (int)v.size(); i++) { cout << '{'; auto a = v[i].F; auto b = v[i].S; pair<bool, bool> isValue = {is_integral<T1>::value, is_integral<T2>::value}; if (isValue.first) { if (a == inf || a == INF) cout << "x,"; else cout << a << ","; } else cout << a << ","; if (isValue.second) { if (b == inf || b == INF) cout << "x,"; else cout << b; } else cout << b; cout << "}" << " \n"[split_line || i + 1 == (int)v.size()]; } } #endif // INCLUDED_MAIN