結果

問題 No.3260 岩井スターグラフ
ユーザー Leal-0
提出日時 2025-09-06 13:26:19
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 556 ms / 2,000 ms
コード長 2,085 bytes
コンパイル時間 2,566 ms
コンパイル使用メモリ 220,700 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-09-06 13:26:50
合計ジャッジ時間 17,667 ms
ジャッジサーバーID
(参考情報)
judge / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /usr/include/c++/13/istream:41,
                 from /usr/include/c++/13/sstream:40,
                 from /usr/include/c++/13/complex:45,
                 from /usr/include/c++/13/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:127,
                 from main.cpp:3:
In member function ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]’,
    inlined from ‘int main()’ at main.cpp:79:15:
/usr/include/c++/13/ostream:204:25: warning: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized]
  204 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: In function ‘int main()’:
main.cpp:63:12: note: ‘ans’ was declared here
   63 |         ll ans;
      |            ^~~

ソースコード

diff #

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define srep(i,l,r) for(ll i=l;i<=r;i++)
#define irep(i,r,l) for(ll i=r;i>=l;i--)
using ll = long long;
using ld = long double;
constexpr ll mod = 998244353ll;
#define vout(v) for(auto i :v) cout<<i<<" ";
#define INF 9223300000000000000ll
#define Winf 5e12
#define nl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define vl vector<ll>
#define pb push_back

#define vc vector<char>
#define vb vector<bool>
#define uniq(x) sort((x).begin(),(x).end());(x).erase(unique((x).begin(),(x).end()),(x).end())
#define eb emplace_back



void no(void) { cout<<"No"<<nl;}
void yes(void) {cout<<"Yes"<<nl;}
void yn(bool a) {
    cout<<(a ? "Yes":"No")<<nl;
}


vector<ll> dx={-1,0,1,0,1,1,-1,-1};
vector<ll> dy={0,-1,0,1,-1,1,-1,1};

bool isin(ll i,ll j,ll h,ll w) {
    if(i<0 || i>=h || j<0 || j>=w) return false;
    return true;
}

template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}


template<class T>T vecmax(const vector<T>&v){return *max_element(all(v));}
template<class T>T vecmin(const vector<T>&v){return *min_element(all(v));}

ll safemod(ll num,ll rule) {
    return (num%rule+rule)%rule;
}
//alias ojb='oj-bundle -I /home/leal/beginner/atc/library'
ll sum(vector<ll> &a) {
    return accumulate(all(a),0ll);
}


int main() {
    ll x,y,n; cin>>x>>y>>n;
    
    rep(i,n) {
        ll u,v; cin>>u>>v;
        ll ans;
        function<ll(ll)> branch=[&](ll p)->ll {
            return (p-1)/y;
        };
        function<ll(ll)> rootdist=[&](ll p)->ll {
            return ((p%y)==0 ? y : p%y);
        };
        if(u==v) {
            ans=0;
        }
        else if(u>v) swap(u,v);
        else if(u==0) {
            ans=rootdist(v);
        }
        else if(branch(u)==branch(v)) ans=abs(u-v);
        else ans=rootdist(u)+rootdist(v);
        cout<<ans<<nl;
        
    }
}
0