結果
| 問題 |
No.390 最長の数列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-08-01 23:30:34 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,173 bytes |
| コンパイル時間 | 803 ms |
| コンパイル使用メモリ | 91,388 KB |
| 実行使用メモリ | 54,272 KB |
| 最終ジャッジ日時 | 2024-10-11 00:30:54 |
| 合計ジャッジ時間 | 4,002 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 12 WA * 3 |
ソースコード
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, string> pls;
#define MAX_N 1000000
int n;
int a[100010];
int used[MAX_N+1];
map<int, int> m;
int main()
{
cin >> n;
int mx = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
m[a[i]] = 1;
mx = max(mx,a[i]);
}
sort(a, a + n);
int num, num_mx = 0,x,ans = 0;
for (int i = 0; i < n - num_mx; i++) {
if (a[i] == 1)continue;
if (used[a[i]])continue;
x = a[i];
for(int k= 1; k * x <= mx; k++){
num = 0;
x = k * a[i];
if (used[k*a[i]])continue;
if (!m[k*a[i]])continue;
for (int j = 1; x * j <= mx; j++) {
if (m[x * j]) {
used[x*j] = 1;
num++;
x = x*j;
j = 1;
}
}
ans = max(ans,num);
x = a[i];
}
num_mx = max(num_mx, ans);
}
if (a[0] == 1)num_mx++;
cout << num_mx << endl;
return 0;
}