結果
| 問題 | No.1036 Make One With GCD 2 |
| コンテスト | |
| ユーザー |
miscalc
|
| 提出日時 | 2026-02-24 16:02:56 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 271 ms / 2,000 ms |
| コード長 | 2,025 bytes |
| 記録 | |
| コンパイル時間 | 3,751 ms |
| コンパイル使用メモリ | 342,920 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2026-02-24 16:03:10 |
| 合計ジャッジ時間 | 11,774 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 41 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define vc vector
using vl = vc<ll>;
#define ov(a, b, c, name, ...) name
#define rep2(i, a, b) for(ll i = (a); i < ll(b); i++)
#define rep1(i, n) rep2(i, 0, n)
#define rep(...) ov(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define fec(...) for(const auto& __VA_ARGS__)
#define per(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
bool chmin(auto& a, auto b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto& a, auto b) { return a < b ? a = b, 1 : 0; }
const ll INF = ll(4e18) + 100;
#define ALL(x) begin(x), end(x)
#define SZ(x) (ll) size(x)
#define LB(v, x) (lower_bound(ALL(v), x) - begin(v))
#define eb emplace_back
void printvec(const auto& v)
{
for (auto it = begin(v); it != end(v); it++) cout << *it << " ";
cout << endl;
}
#ifdef LOCAL
#define local(...) __VA_ARGS__
#else
#define local(...)
#endif
using u64 = uint64_t;
u64 ctz(u64 x) { return countr_zero(x); }
u64 binary_gcd(u64 x, u64 y) {
if(!x || !y) return x | y;
u64 n = ctz(x), m = ctz(y);
x >>= n, y >>= m;
while(x != y) {
if(x > y) x = (x - y) >> ctz(x - y);
else y = (y - x) >> ctz(y - x);
}
return x << min(n, m);
}
void main2()
{
ll N;
cin >> N;
vl A(N);
rep(i, N) cin >> A[i];
ll ans = 0;
vc<pll> dp;
fec(a : A)
{
for(auto &[g, cnt] : dp) g = gcd(g, a);
dp.eb(a, 1);
ll k = 0;
rep(j, 1, dp.size())
{
if (dp[k].first == dp[j].first) dp[k].second += dp[j].second;
else k++, dp[k] = dp[j];
}
dp.resize(k + 1);
if (dp.front().first == 1) ans += dp.front().second;
local(cout << "a=" << a << endl; fec([g, cnt] : dp) cout << "g=" << g << " cnt=" << cnt << endl);
}
cout << ans << endl;
}
int main()
{
#ifndef LOCAL
cin.tie(0)->sync_with_stdio(0), cout.tie(0);
#endif
local(while(true)) {
ll t = 1;
// cin >> t;
while (t--) main2();
}
}
miscalc