結果
| 問題 | No.3441 Sort Permutation 2 |
| コンテスト | |
| ユーザー |
👑 potato167
|
| 提出日時 | 2026-02-05 17:07:19 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 763 bytes |
| 記録 | |
| コンパイル時間 | 1,900 ms |
| コンパイル使用メモリ | 215,160 KB |
| 実行使用メモリ | 12,836 KB |
| 最終ジャッジ日時 | 2026-02-06 20:58:31 |
| 合計ジャッジ時間 | 6,141 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 TLE * 1 -- * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<int> p(N);
rep(i, 0, N) cin >> p[i], p[i]--;
vector<int> ans(N);
rep(i, 0, N) if (p[i] != -1){
int g = 0;
int sz = 0;
vector<int> q;
while (p[i] != -1){
int nx = p[i];
for (auto x : q) g = gcd(g, abs(x - nx));
q.push_back(nx);
p[i] = -1;
i = nx;
sz++;
}
ans[g] += sz - 1;
}
rep(i, 1, N){
for (int j = i * 2; j < N; j += i){
ans[i] += ans[j];
}
cout << ans[i] << "\n";
}
}
potato167