結果

問題 No.2119 一般化百五減算
ユーザー KudeKude
提出日時 2022-11-04 21:38:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,457 bytes
コンパイル時間 2,424 ms
コンパイル使用メモリ 230,964 KB
実行使用メモリ 5,200 KB
最終ジャッジ日時 2023-09-25 23:55:57
合計ジャッジ時間 3,661 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
4,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
4,380 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,380 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1 ms
4,376 KB
testcase_19 WA -
testcase_20 AC 22 ms
4,384 KB
testcase_21 WA -
testcase_22 AC 32 ms
4,380 KB
testcase_23 AC 30 ms
4,380 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic pop
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<P> bc(m);
  for(auto& [b, c]: bc) {
    cin >> b >> c;
    c = (c % b + b) % b;
  }
  sort(all(bc));
  bool ok = true;
  rep(i, m - 1) if (bc[i].first == bc[i+1].first) {
    if (bc[i].second != bc[i+1].second) {
      ok = false;
      break;
    } else {
      bc[i+1] = bc[i];
    }
  }
  if (!ok) {
    cout << "Nan\n";
    return 0;
  }
  bc.erase(unique(all(bc)), bc.end());
  m = bc.size();
  VI cnt(n);
  for(auto [b, c]: bc) {
    for(int i = c; i < n; i += b) cnt[i]++;
  }
  ok = false;
  rep(i, n) if (cnt[i] == m) {
    ok = true;
    cout << i << '\n';
    break;
  }
  if (!ok) {
    cout << "Nan\n";
  }
}
0