結果

問題 No.390 最長の数列
ユーザー XelmephXelmeph
提出日時 2016-07-09 00:01:40
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,328 bytes
コンパイル時間 1,014 ms
コンパイル使用メモリ 78,488 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-21 08:48:39
合計ジャッジ時間 7,514 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 21 ms
5,376 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <fstream>
#include <stdint.h>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = (n)-1; i >= 0; i--)
#define FOR(i, l, r) for(int i = l; i < r; i++)
#define RFOR(i, l,r) for(int i= (l)-1; i>= (r) ; i--)

constexpr int INF       = -1000000000;/* 1e+9a */
constexpr int MODULO    = 1000000007;

int max_v = 1;
vector<int> depth;

int calc(vector<int>& p, int n = 0, int dep = 1)
{
    int thi = n;
    if(depth[n] != INF)
        return depth[n];
    int t_max = dep;
    FOR(i, n+1, p.size())
    {
        if(p[i] % p[thi] == 0)
        {
            int tmp = calc(p, i, dep+1);
            t_max = t_max > tmp ? t_max : tmp;
        }
    }
    return depth[thi] = t_max;
}

int solve(vector<int>& p)
{
    calc(p);
    int tmp = *max_element(depth.begin(), depth.end());
    return tmp == INF ? 1 : tmp;
}   

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> p;
    REP(i, n)
    {
        int tmp;
        cin >> tmp;
        p.push_back(tmp);
    }
    sort(p.begin(),p.end());
    REP(i, n)
    {
        depth.push_back(INF);
    }
    cout << solve(p)  << '\n';

}
0