結果

問題 No.1200 お菓子配り-3
ユーザー beetbeet
提出日時 2020-08-28 21:47:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,395 bytes
コンパイル時間 2,261 ms
コンパイル使用メモリ 210,820 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-09 08:05:03
合計ジャッジ時間 17,287 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 13 ms
4,376 KB
testcase_08 AC 13 ms
4,376 KB
testcase_09 AC 12 ms
4,380 KB
testcase_10 AC 12 ms
4,376 KB
testcase_11 AC 11 ms
4,380 KB
testcase_12 AC 106 ms
4,376 KB
testcase_13 AC 109 ms
4,376 KB
testcase_14 AC 109 ms
4,376 KB
testcase_15 AC 113 ms
4,376 KB
testcase_16 AC 110 ms
4,380 KB
testcase_17 AC 392 ms
4,376 KB
testcase_18 AC 556 ms
4,376 KB
testcase_19 AC 132 ms
4,376 KB
testcase_20 AC 1,086 ms
4,380 KB
testcase_21 AC 1,068 ms
4,376 KB
testcase_22 AC 1,283 ms
4,380 KB
testcase_23 AC 1,085 ms
4,376 KB
testcase_24 AC 1,059 ms
4,380 KB
testcase_25 AC 1,068 ms
4,376 KB
testcase_26 AC 1,085 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 666 ms
4,376 KB
testcase_29 AC 1,852 ms
4,380 KB
testcase_30 AC 1,881 ms
4,376 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=Int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}

//INSERT ABOVE HERE
using P = pair<Int, Int>;
map<P, Int> memo;
signed solve(){
  Int x,y;
  cin>>x>>y;
  if(x>y) swap(x,y);
  if(memo.count(P(x,y))){
    cout<<memo[P(x,y)]<<newl;
    return 0;
  }
  Int &res=memo[P(x,y)];
  res=0;

  if(x==y){
    vector<Int> cand;
    for(Int i=1;i*i<=x;i++){
      if(x%i) continue;
      cand.emplace_back(i);
      if(i*i!=x) cand.emplace_back(x/i);
    }
    for(Int c:cand){
      Int a=x/c-1;
      if(0<a) res++;
    }
    cout<<res<<newl;
    return 0;
  }

  Int d=y-x;
  vector<Int> cand;
  for(Int i=1;i*i<=d;i++){
    if(d%i) continue;
    cand.emplace_back(i);
    if(i*i!=d) cand.emplace_back(d/i);
  }

  for(Int t:cand){
    Int a=t+1;
    Int s=d/t;
    Int b=(x-s)/(a+1);
    Int c=s+b;
    if(0<a and 0<b and 0<c and a*b+c==x and a*c+b==y) res++;
  }

  cout<<res<<newl;
  return 0;
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int T;
  cin>>T;
  while(T--) solve();
  return 0;
}
0