結果

問題 No.1884 Sequence
ユーザー h-izuh-izu
提出日時 2023-04-30 22:25:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 6,478 bytes
コンパイル時間 4,720 ms
コンパイル使用メモリ 282,924 KB
実行使用メモリ 9,648 KB
最終ジャッジ日時 2023-08-12 11:23:38
合計ジャッジ時間 10,875 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 57 ms
9,368 KB
testcase_11 AC 56 ms
9,472 KB
testcase_12 AC 11 ms
4,468 KB
testcase_13 AC 12 ms
4,384 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 49 ms
9,304 KB
testcase_17 AC 20 ms
5,904 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 52 ms
9,432 KB
testcase_24 AC 51 ms
9,428 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 14 ms
4,912 KB
testcase_28 AC 13 ms
4,668 KB
testcase_29 AC 15 ms
4,656 KB
testcase_30 AC 13 ms
4,752 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 37 ms
9,312 KB
testcase_34 AC 41 ms
9,500 KB
testcase_35 AC 16 ms
5,084 KB
testcase_36 AC 30 ms
7,212 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 44 ms
8,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

#include <atcoder/all>
using namespace std;
using namespace atcoder;

typedef unsigned long long ull;
typedef long long ll;

const double PI = 3.14159265358979323846;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll powpow(ll a, ll p) {
  if (p == 0) return 1;

  if (p % 2 == 0) {
    ll half = powpow(a, p / 2);
    return half * half;
  } else {
    return a * powpow(a, p - 1);
  }
}

class combination {
 private:
  ll N;
  vector<vector<ll>> C;

 public:
  explicit combination(ll _n) : N(_n) {
    C.resize(N + 1);
    rep(i, N + 1) C[i].resize(N + 1);
    C[0][0] = 1;
    rep(i, N) rep(j, i + 1) {
      C[i + 1][j + 1] += C[i][j];
      C[i + 1][j] += C[i][j];
    }
  }

  ll operator()(ll n, ll k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return C[n][k];
  }
};

// ref. https://drken1215.hatenablog.com/entry/2018/06/08/210000
class modcombination {
 private:
  ll mod;
  vector<ll> fac, finv, inv;

 public:
  modcombination(ll n, ll _mod) : mod(_mod) {
    fac.resize(n + 1);
    finv.resize(n + 1);
    inv.resize(n + 1);

    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;

    for (ll i = 2; i <= n; i++) {
      fac[i] = fac[i - 1] * i % mod;
      inv[i] = mod - inv[mod % i] * (mod / i) % mod;
      finv[i] = finv[i - 1] * inv[i] % mod;
    }
  }

  ll operator()(ll n, ll k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
  }
};

// cf. https://qiita.com/drken/items/a14e9af0ca2d857dad23
vector<ll> enum_divisors(ll n) {
  vector<ll> res;
  // sqrt(n)まで試し割り
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      // 重複しないならばiの相方であるn/iも約数
      // e.g. n=25のときのi=5は重複
      if (n / i != i) res.push_back(n / i);
    }
  }

  sort(res.begin(), res.end());
  return res;
}

// cf. https://qiita.com/drken/items/a14e9af0ca2d857dad23
map<ll, ll> prime_factors(ll n) {
  map<ll, ll> res;
  // sqrt(n)まで試し割り
  for (ll a = 2; a * a <= n; a++) {
    if (n % a != 0) continue;

    // nで割れる限り割る
    while (n % a == 0) {
      res[a]++;
      n /= a;
    }
  }
  if (n != 1) res[n]++;

  return res;
}

// p/q
struct fraction {
  ll p, q;
  fraction(ll _p = 0, ll _q = 1) : p(_p), q(_q) {
    if (q == 0) {
      p = 1;
      return;
    }
    if (q < 0) {
      p = -p;
      q = -q;
    }

    ll g = gcd(p, q);
    p /= g;
    q /= g;
  }

  bool operator<(const fraction& other) const {
    return p * other.q < q * other.p;
  }

  bool operator<=(const fraction& other) const {
    return p * other.q <= q * other.p;
  }

  bool operator==(const fraction& other) const {
    return p == other.p && q == other.q;
  }
};

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<ll>> calcNext(const string& S) {
  ll n = (ll)S.size();
  vector<vector<ll>> res(n + 1, vector<ll>(26, n));
  for (ll i = n - 1; i >= 0; --i) {
    for (ll j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
    res[i][S[i] - 'a'] = i;
  }
  return res;
}

// ref. https://algo-logic.info/bridge-lowlink/
struct LowLink {
  vector<vector<ll>> G;
  vector<ll> ord, low;
  vector<bool> visited;
  vector<pair<ll, ll>> bridges;

  explicit LowLink(const vector<vector<ll>>& _G) : G(_G) {
    visited.resize(G.size(), false);
    ord.resize(G.size(), 0);
    low.resize(G.size(), 0);
    ll k = 0;
    rep(i, (ll)G.size()) {
      if (visited[i]) continue;
      k = dfs(i, k);
    }
  }

  ll dfs(ll node, ll k, ll parent = -1) {
    visited[node] = true;
    ord[node] = k;
    low[node] = k;
    k++;
    for (auto g : G[node]) {
      if (!visited[g]) {
        k = dfs(g, k, node);
        low[node] = min(low[node], low[g]);
        if (ord[node] < low[g]) {
          bridges.emplace_back(node, g);
        }
      } else if (g != parent) {
        low[node] = min(low[node], ord[g]);
      }
    }

    return k;
  }
};

// 3x3(アフィン変換)
struct matrix {
  vector<vector<ll>> a;
  matrix(const vector<vector<ll>>& _a = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}})
      : a(_a) {}
  matrix operator*(const matrix& x) {
    matrix res({{0, 0, 0}, {0, 0, 0}, {0, 0, 0}});
    rep(i, 3) rep(j, 3) rep(k, 3) {
      // cout << i << "," << j << " <- " << a[i][k] << "*" << x.a[k][j] << endl;
      res.a[i][j] += a[i][k] * x.a[k][j];
    }

    return res;
  }

  vector<ll> operator*(const vector<ll>& x) {
    matrix other({{x[0], 0, 0}, {x[1], 0, 0}, {1, 0, 0}});
    auto res = *this * other;
    return vector<ll>({res.a[0][0], res.a[1][0], res.a[2][0]});
  }
};

ll inverse_number(const vector<ll>& a) {
  ll n = a.size();
  ll ret = 0;
  fenwick_tree<ll> t(n);
  rep(i, n) {
    ret += t.sum(a[i] + 1, n);
    t.add(a[i], 1);
  }
  return ret;
}

ll swap_distance(const vector<ll>& a, const vector<ll>& b) {
  if (a.size() != b.size()) {
    return -1;
  }
  ll n = a.size();
  using P = pair<ll, ll>;
  vector<P> _a(n), _b(n);
  rep(i, n) {
    _a[i] = {a[i], i};
    _b[i] = {b[i], i};
  }
  sort(_a.begin(), _a.end());
  sort(_b.begin(), _b.end());

  vector<ll> p(n);
  rep(i, n) {
    auto [va, ai] = _a[i];
    auto [vb, bi] = _b[i];
    if (va != vb) {
      return -1;
    }
    p[ai] = bi;
  }
  return inverse_number(p);
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  vector<ll> b;
  rep(i, n) {
    if (a[i] == 0) continue;
    b.push_back(a[i]);
  }
  ll l = b.size();
  vector<ll> c;
  for (ll i = 0; i + 1 < l; i++) {
    c.push_back(b[i + 1] - b[i]);
  }
  ll g = 0;
  for (auto v : c) {
    g = gcd(g, v);
  }

  if (g == 1) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

  return 0;
}
0