結果
問題 | No.2821 A[i] ← 2A[j] - A[i] |
ユーザー |
![]() |
提出日時 | 2024-07-26 22:50:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 630 ms / 1,500 ms |
コード長 | 539 bytes |
コンパイル時間 | 2,135 ms |
コンパイル使用メモリ | 199,676 KB |
最終ジャッジ日時 | 2025-02-23 18:52:26 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 33 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; cin >> n; set<ll> st; ll g = 0; for (int i = 0; i < n; i++) { ll a; cin >> a; if (i == 0) { st.insert(a); } else { if (!st.count(a)) { auto nxt = st.lower_bound(a); if (nxt != st.end()) { g = gcd(g, *nxt - a); } if (nxt != st.begin()) { auto prv = prev(nxt); g = gcd(g, a - *prv); } st.insert(a); } } cout << g << endl; } }