結果
問題 | No.2609 Decreasing GCDs |
ユーザー |
|
提出日時 | 2024-01-19 21:39:02 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 954 bytes |
コンパイル時間 | 3,201 ms |
コンパイル使用メモリ | 253,820 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-28 04:09:00 |
合計ジャッジ時間 | 3,575 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 22 |
ソースコード
#include <bits/stdc++.h>// #include <x86intrin.h>using namespace std;#if __cplusplus >= 202002Lusing namespace numbers;#endifint main(){cin.tie(0)->sync_with_stdio(0);cin.exceptions(ios::badbit | ios::failbit);int n;cin >> n;vector<int> a(n);a[n - 1] = 1;for(auto i = n - 2; i >= 1; -- i){a[i] = (2 * (n - 2 - i) + 1) * (2 * (n - 2 - i) + 3);}a[0] = 2 * n - 3;for(auto i = 1; i < n; ++ i){if(a[i - 1] >= a[i]){int x = a[i];int pg = gcd(a[i - 1], a[i]);int ng = i + 1 < n ? gcd(a[i], a[i + 1]) : 0;while(a[i] <= a[i - 1] || gcd(a[i - 1], a[i]) != pg || i + 1 < n && gcd(a[i], a[i + 1]) != ng){a[i] += x;}}}ranges::copy(a, ostream_iterator<int>(cout, " "));cout << endl;assert(ranges::max(a) <= 100'000'000);for(auto i = 0; i < n - 1; ++ i){assert(a[i] < a[i + 1]);}for(auto i = 1; i < n - 1; ++ i){assert(gcd(a[i - 1], a[i]) > gcd(a[i], a[i + 1]));}return 0;}/**/