結果
| 問題 | 
                            No.2119 一般化百五減算
                             | 
                    
| コンテスト | |
| ユーザー | 
                             259_Momone
                         | 
                    
| 提出日時 | 2022-11-04 23:09:38 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 83 ms / 2,000 ms | 
| コード長 | 939 bytes | 
| コンパイル時間 | 2,820 ms | 
| コンパイル使用メモリ | 256,288 KB | 
| 最終ジャッジ日時 | 2025-02-08 18:20:35 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 25 | 
ソースコード
#include <bits/extc++.h>
int main() {
    using namespace std;
    unsigned long N, M;
    cin >> N >> M;
    vector<pair<unsigned long, unsigned long>> v(M);
    for(auto&& [B, C] : v){
        cin >> B;
        long c;
        cin >> c;
        C = (c % static_cast<long>(B) + B) % B;
    }
    sort(begin(v), end(v), greater<>{});
    for(unsigned long i{1}; i < M; ++i)if(v[i - 1].first == v[i].first && v[i - 1].second != v[i].second){
        cout << "NaN" << endl;
        return 0;
    }
    v.erase(unique(begin(v), end(v)), end(v));
    vector<unsigned long> possible(N + 1);
    iota(begin(possible), end(possible), 0UL);
    for(const auto& [B, C] : v){
        possible.erase(remove_if(begin(possible), end(possible), [&B, &C](auto&& i){return i % B != C;}), end(possible));
        if(empty(possible)){
            cout << "NaN" << endl;
            return 0;
        }
    }
    cout << possible[0] << endl;
    return 0;
}
            
            
            
        
            
259_Momone