結果

問題 No.2119 一般化百五減算
コンテスト
ユーザー chro_96
提出日時 2022-11-04 21:53:11
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 837 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 180 ms
コンパイル使用メモリ 38,720 KB
最終ジャッジ日時 2026-02-22 09:42:13
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>

int main () {
  int n = 0;
  int m = 0;
  int b[100000] = {};
  int c[100000] = {};
  
  int res = 0;
  
  int prev[100001] = {};
  
  int ap[100001] = {};
  int cnt = 0;
  int is_ok = 1;
  
  int ans = 0;
  
  res = scanf("%d", &n);
  res = scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    res = scanf("%d", b+i);
    res = scanf("%d", c+i);
    if (c[i] < 0) {
      c[i] += (1+(-c[i])/b[i])*b[i];
    }
    if (prev[b[i]] > 0) {
      int idx = prev[b[i]]-1;
      if (c[i]%b[i] == c[idx]%b[idx]) {
        is_ok = 0;
      }
    } else {
      for (int j = c[i]%b[i]; j <= n; j += b[i]) {
        ap[j]++;
      }
      cnt++;
    }
    prev[b[i]] = i+1;
  }
  
  while (ans <= n) {
    if (ap[ans] >= cnt) {
      printf("%d\n", ans);
      return 0;
    }
    ans++;
  }
  
  printf("NaN\n");
  return 0;
}
0