結果

問題 No.2119 一般化百五減算
ユーザー 259_Momone259_Momone
提出日時 2022-11-04 22:03:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 926 bytes
コンパイル時間 2,714 ms
コンパイル使用メモリ 266,704 KB
実行使用メモリ 5,420 KB
最終ジャッジ日時 2023-09-26 00:28:08
合計ジャッジ時間 4,178 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#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));
    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;
}
0