結果

問題 No.2811 Calculation Within Sequence
ユーザー tobbie
提出日時 2024-08-02 23:28:20
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 210 ms / 2,000 ms
コード長 780 bytes
コンパイル時間 2,077 ms
コンパイル使用メモリ 172,500 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-08-02 23:28:31
合計ジャッジ時間 11,169 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

int main() {
  int a, b;
  cin >> a >> b;
  vector<int> t(a), s(b);
  rep(i, a)
    cin >> t[i];
  rep(i, b)
    cin >> s[i];
  sort(t.begin(), t.end());
  vector<int> tDif;
  int tOdd = 0, tEven = 0;
  rep(i, a) {
    if (t[i] % 2 == 0)
      tEven++;
    else
      tOdd++;
    if (i > 0) {
      if (t[i] != t[i-1])
	tDif.push_back(abs(t[i] - t[i-1]));
    }
  }
  sort(tDif.begin(), tDif.end());
  bool ans = true;
  rep(i, b) {
    if ((int)tDif.size() == 0) {
      if (s[i] % t[0] != 0)
	ans = false;
    } else {
      if (s[i] % t[0] != 0 && s[i] % tDif[0] != 0)
	ans = false;
    }
  }
  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
0