結果

問題 No.250 atetubouのzetubou
ユーザー not_522not_522
提出日時 2015-08-04 11:53:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 526 ms / 5,000 ms
コード長 2,308 bytes
コンパイル時間 1,263 ms
コンパイル使用メモリ 150,104 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-25 01:01:13
合計ジャッジ時間 8,820 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 305 ms
4,376 KB
testcase_01 AC 54 ms
4,376 KB
testcase_02 AC 461 ms
4,376 KB
testcase_03 AC 526 ms
4,376 KB
testcase_04 AC 454 ms
4,376 KB
testcase_05 AC 470 ms
4,376 KB
testcase_06 AC 364 ms
4,376 KB
testcase_07 AC 177 ms
4,376 KB
testcase_08 AC 434 ms
4,376 KB
testcase_09 AC 328 ms
4,376 KB
testcase_10 AC 473 ms
4,380 KB
testcase_11 AC 283 ms
4,380 KB
testcase_12 AC 430 ms
4,384 KB
testcase_13 AC 234 ms
4,376 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 246 ms
4,376 KB
testcase_16 AC 248 ms
4,380 KB
testcase_17 AC 244 ms
4,380 KB
testcase_18 AC 244 ms
4,380 KB
testcase_19 AC 248 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

template<typename T> inline T gcd(T a, T b) {
  return __gcd(a, b);
}

template<typename T> inline T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}

template<typename T> inline T floor(T a, T b) {
  return a / b * b <= a ? a / b : a / b - 1;
}

template<typename T> inline T ceil(T a, T b) {
  return floor(a + b - 1, b);
}

template<typename T> inline T round(T a, T b) {
  return floor(a + b / 2);
}

template<typename T> inline T mod(T a, T b) {
  return a - floor(a, b) * b;
}

template<typename T> inline T factorial(T n) {
  return n <= 1 ? 1 : factorial(n - 1) * n;
}

template<typename T> class Combination {
private:
  vector<vector<T>> comb;
  
public:
  Combination(int n = 0) : comb(n, vector<T>(n, 0)) {
    for (int i = 0; i < n; ++i) comb[i][0] = 1;
    for (int i = 1; i < n; ++i) {
      for (int j = 1; j < n; ++j) {
        comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
      }
    }
  }

  T combination(int n, int m) {
    if (n < m) return 0;
    if (n < (int)comb.size()) return comb[n][m];
    T res = 1;
    for (int i = 0; i < min(m, n - m); ++i) res = res * (n - i) / (i + 1);
    return res;
  }

  T combination_safety(int n, int m) {
    if (n < m) return 0;
    if (n < (int)comb.size()) return comb[n][m];
    m = min(m, n - m);
    vector<int> a(m), b(m);
    iota(a.begin(), a.end(), n - m + 1);
    iota(b.begin(), b.end(), 1);
    for (auto i : b) {
      for (auto& j : a) {
        auto g = gcd(i, j);
        i /= g;
        j /= g;
        if (i == 1) break;
      }
    }
    return accumulate(a.begin(), a.end(), T(1), multiplies<T>());
  }

  T repetition(int n, int r) {
    return combination(n + r - 1, r);
  }
};

int main() {
  int q;
  cin >> q;
  Combination<long long> comb;
  for (int i = 0; i < q; ++i) {
    long long d, x, t;
    cin >> d >> x >> t;
    if (t == 0) {
      cout << "ZETUBOU" << endl;
      continue;
    }
    double sum = 0, limit = log(t);
    for (int i = 1; i <= d + x - 1; ++i) sum += log(i);
    for (int i = 1; i <= x; ++i) sum -= log(i);
    for (int i = 1; i <= d - 1; ++i) sum -= log(i);
    if (sum > limit + 1) {
      cout << "ZETUBOU" << endl;
      continue;
    }
    long long s = comb.combination(d + x - 1, x);
    cout << (s <= t ? "AC" : "ZETUBOU") << endl;
  }
}
0