結果

問題 No.1200 お菓子配り-3
ユーザー HaarHaar
提出日時 2020-08-28 22:02:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,403 bytes
コンパイル時間 2,173 ms
コンパイル使用メモリ 204,492 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-09 08:21:51
合計ジャッジ時間 19,012 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 13 ms
4,380 KB
testcase_08 AC 13 ms
4,380 KB
testcase_09 AC 13 ms
4,380 KB
testcase_10 AC 13 ms
4,380 KB
testcase_11 AC 12 ms
4,384 KB
testcase_12 AC 108 ms
4,380 KB
testcase_13 AC 110 ms
4,376 KB
testcase_14 AC 111 ms
4,376 KB
testcase_15 AC 113 ms
4,376 KB
testcase_16 AC 110 ms
4,380 KB
testcase_17 AC 398 ms
4,380 KB
testcase_18 AC 570 ms
4,380 KB
testcase_19 AC 131 ms
4,376 KB
testcase_20 AC 1,098 ms
4,380 KB
testcase_21 AC 1,097 ms
4,384 KB
testcase_22 AC 1,291 ms
4,380 KB
testcase_23 AC 1,099 ms
4,376 KB
testcase_24 AC 1,080 ms
4,376 KB
testcase_25 AC 1,086 ms
4,380 KB
testcase_26 AC 1,091 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 863 ms
4,380 KB
testcase_29 AC 2,418 ms
4,380 KB
testcase_30 AC 2,413 ms
4,380 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

template <typename T, typename U>
bool chmin(T &a, const U &b){
  return (a > b ? a = b, true : false);
}

template <typename T, typename U>
bool chmax(T &a, const U &b){
  return (a < b ? a = b, true : false);
}

template <typename T, size_t N, typename U>
void fill_array(T (&a)[N], const U &v){
  std::fill((U*)a, (U*)(a + N), v);
}

template <typename T>
auto make_vector(int n, int m, const T &value){
  return std::vector<std::vector<T>>(n, std::vector<T>(m, value));
}

template <typename T>
std::ostream& operator<<(std::ostream &s, const std::vector<T> &a){
  for(auto it = a.begin(); it != a.end(); ++it){
    if(it != a.begin()) s << " ";
    s << *it;
  }
  return s;
}

template <typename T>
std::istream& operator>>(std::istream &s, std::vector<T> &a){
  for(auto &x : a) s >> x;
  return s;
}

/**
 * @title Enumerate divisors
 * @docs enumerate_divisors.md
 */
std::vector<int64_t> enumerate_divisors(int64_t n){
  std::vector<int64_t> temp, ret;

  {
    int64_t i;
    for(i = 1LL; i * i < n; ++i){
      if(n%i == 0){
        temp.push_back(n / i);
        ret.push_back(i);
      }
    }
    if(i * i == n) ret.push_back(i);
  }

  std::reverse(temp.begin(), temp.end());
  ret.insert(ret.end(), temp.begin(), temp.end());
  
  return ret;
}



namespace solver{
  void init(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(12);
    std::cerr << std::fixed << std::setprecision(12);
    std::cin.exceptions(std::ios_base::failbit);
  }
  
  void solve(){
    int S; std::cin >> S;
    while(S--){
      int X, Y; std::cin >> X >> Y;

      if(X < Y) std::swap(X, Y);
      int diff = X - Y;
      int64_t ans = 0;

      for(auto div : enumerate_divisors(diff)){
        int A = div + 1;
        if((X + Y) % (A + 1)) continue;

        int d1 = diff / div;
        int d2 = (X + Y) / (A + 1);

        int B = (d1 + d2) / 2;
        int C = d2 - B;
        //dump(std::make_tuple(A, B, C));
        
        if(B > 0 and C > 0){
          if(X == A * B + C and Y == A * C + B) ++ans;
        }
      }

      std::cout << ans << "\n";
    }
  }
}

int main(){
  solver::init();
  while(true){
    try{
      solver::solve();
    }catch(const std::istream::failure &e){
      break;
    }
  }
  return 0;
}
0