結果
| 問題 | 
                            No.2119 一般化百五減算
                             | 
                    
| コンテスト | |
| ユーザー | 
                             chro_96
                         | 
                    
| 提出日時 | 2022-11-05 18:03:53 | 
| 言語 | C  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 29 ms / 2,000 ms | 
| コード長 | 899 bytes | 
| コンパイル時間 | 1,007 ms | 
| コンパイル使用メモリ | 28,800 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-07-19 10:19:11 | 
| 合計ジャッジ時間 | 1,577 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 25 | 
ソースコード
#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;
  }
  
  if (is_ok <= 0) {
    printf("NaN\n");
    return 0;
  }
  
  while (ans <= n) {
    if (ap[ans] >= cnt) {
      printf("%d\n", ans);
      return 0;
    }
    ans++;
  }
  
  printf("NaN\n");
  return 0;
}
            
            
            
        
            
chro_96