結果
問題 | No.2119 一般化百五減算 |
ユーザー |
![]() |
提出日時 | 2022-11-04 22:03:09 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 82 ms / 2,000 ms |
コード長 | 926 bytes |
コンパイル時間 | 4,038 ms |
コンパイル使用メモリ | 256,492 KB |
最終ジャッジ日時 | 2025-02-08 17:46:57 |
ジャッジサーバー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)); 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; }