結果

問題 No.2259 Gas Station
ユーザー cumincumin
提出日時 2023-04-08 05:34:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,305 bytes
コンパイル時間 4,588 ms
コンパイル使用メモリ 277,536 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-03 03:10:59
合計ジャッジ時間 4,216 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 WA -
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 2 ms
5,248 KB
testcase_06 AC 2 ms
5,248 KB
testcase_07 AC 2 ms
5,248 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
5,248 KB
testcase_11 AC 2 ms
5,248 KB
testcase_12 AC 3 ms
5,248 KB
testcase_13 AC 2 ms
5,248 KB
testcase_14 AC 2 ms
5,248 KB
testcase_15 AC 2 ms
5,248 KB
testcase_16 AC 2 ms
5,248 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
5,248 KB
testcase_20 AC 2 ms
5,248 KB
testcase_21 AC 2 ms
5,248 KB
testcase_22 AC 2 ms
5,248 KB
testcase_23 AC 2 ms
5,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define ll long long
#define ld long double
#define ull unsigned long long
#define _overload4(_1,_2,_3,_4,name,...) name
#define _overload3(_1,_2,_3,name,...) name
#define _rep1(n) for(ll i = 0; i < n; ++i)
#define _rep2(i, n) for(ll i = 0; i < n; ++i)
#define _rep3(i, a, b) for(ll i = a; i < b; ++i)
#define _rep4(i, a, b, c) for(ll i = a; i < b; i += c)
#define rep(...) _overload4(__VA_ARGS__, _rep4, _rep3, _rep2, _rep1)(__VA_ARGS__)
#define rrep(i, n) for(int i = (n)-1; i >= 0; i--)
#define rrep2(i, a, b) for(int i = (a)-1; i >= b; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define eb emplace_back
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define endl '\n'
//using Bint = __int128_t;
template<class T> using pq = priority_queue< T >;
template<class T> using pqg = priority_queue< T , vector< T >, greater< T >>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>
T ceil_div(T a, T b) {
    if(b < 0) a = -a, b = -b;
    return (a >= 0 ? (a + b - 1) / b : a / b);
}
 
template<class T>
T floor_div(T a, T b) {
    if(b < 0) a = -a, b = -b;
    return (a >= 0 ? a / b : (a - b + 1) / b);
}
inline ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll digit(ll x){
  string s = to_string(x);
  return (ll)s.size();
}

const int inf = 1001001001;
const ll INF = 1001001001001001001;

const double PI = acos(-1);

bool range(ll y, ll x, ll h, ll w){
  return (0 <= y && y < h && 0 <= x && x < w);
}
int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};

//using mint = modint998244353;
//const int MOD = 998244353;
//using mint = modint1000000007;
const int MOD = 1000000007;

template<class T> vector< T > compress(vector< T > a){
  auto b = a;
  sort(b.begin(), b.end());
  b.erase(unique(b.begin(), b.end()), b.end());
  int n = a.size();
  for(auto& x : a) x = lower_bound(b.begin(), b.end(), x) - b.begin();
  return a;
}
pair<vector<int>, vector<int>> bfs(vector<vector<int>> &G, int s){
  int n = G.size();
  vector<int> dist(n, inf);
  vector<int> from(n, -1);
  dist[s] = 0;
  queue<int> que;
  que.push(s);
  while(!que.empty()){
    int v = que.front();
    que.pop();
    for(int nv : G[v]){
      if(dist[nv] != inf) continue;
      dist[nv] = dist[v] + 1;
      from[nv] = v;
      que.push(nv);
    }
  }
  return {dist, from};
}
ll modpow(ll a, ll n, ll mod){
  if(n == 0)return 1;
  if(n%2 == 0){
    ll t = modpow(a, n/2, mod);
    return (t*t)%mod;
  }
  return a*modpow(a, n-1, mod)%mod;
}
pair<vector<ll>, vector<int>> dijkstra(vector<vector<pll>> &G, int s){
  int n = G.size();
  vector<ll> dist(n, INF);
  vector<int> prev(n, -1);
  dist[s] = 0;
  pqg<pll> que;
  que.push({0, s});
  while(!que.empty()){
    auto[c, v] = que.top();
    que.pop();
    if(dist[v] != c) continue;
    for(auto[nv, add] : G[v]){
      if(dist[nv] > dist[v] + add){
        dist[nv] = dist[v] + add;
        prev[nv] = v;
        que.push({dist[nv], nv});
      }
    }
  }
  return {dist, prev};
}
void Yes(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
}
// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}
signed main(){

  cout << fixed << setprecision(15);
  
  ll L, R, C;
  ll Z = 1000;
  cin >> L >> R >> C;
  ll ans = Z;
  rep(res, 1, Z+1){
    if(res%gcd(C, Z) != 0) continue;
    ll g = gcd(C, Z);
    ll x, k;
    extGCD(C, -Z, x, k);
    ll d = res/g;
    x *= d;
    k *= g;
    ll mt = ceil_div(L-x, Z/g);
    if((Z/g)*mt+x <= R){
      //cout << res << endl;
      chmin(ans, 1000-res);
    }
  }
  cout << ans << endl;
  
  return 0;
}
0