結果

問題 No.390 最長の数列
ユーザー h_nosonh_noson
提出日時 2016-07-09 00:30:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 931 ms / 5,000 ms
コード長 1,127 bytes
コンパイル時間 734 ms
コンパイル使用メモリ 77,844 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2024-04-10 08:53:48
合計ジャッジ時間 4,673 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 427 ms
8,832 KB
testcase_06 AC 931 ms
8,576 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 404 ms
8,832 KB
testcase_11 AC 406 ms
8,704 KB
testcase_12 AC 407 ms
8,704 KB
testcase_13 AC 204 ms
7,552 KB
testcase_14 AC 311 ms
8,576 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 16 ms
6,944 KB
testcase_18 AC 26 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:38:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 |     scanf("%d",&N);
      |     ~~~~~^~~~~~~~~
main.cpp:39:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |     rep (i,N) scanf("%d",&X[i]);
      |               ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP (i,0,(int)(n)-1)
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP (i,(int)(n)-1,0)

const int INF = 1e8;
const int MOD = 1e9+7;

typedef long long ll;

int X[100000];

vector<int> get_divisor(int n) {
    int i;
    vector<int> a, b;
    for (i = 1; i * i < n; i++) {
        if (n % i == 0) {
            a.push_back(i);
            b.push_back(n/i);
        }
    }
    if (i * i == n)
        a.push_back(i);
    reverse(b.begin(),b.end());
    for (auto x : b)
        a.push_back(x);
    return a;
}

int main(void) {
    int i, N;
    scanf("%d",&N);
    rep (i,N) scanf("%d",&X[i]);

    sort(X,X+N);
    map<int,int> mp;
    rep (i,N) {
        int ma = 0;
        vector<int> d = get_divisor(X[i]);
        for (auto x : d) if (mp.count(x)) {
            ma = max(ma,mp[x]);
        }
        mp[X[i]] = ma + 1;
    }
    int ans = 0;
    for (auto p : mp) {
        ans = max(ans,p.second);
    }
    printf("%d\n",ans);
    return 0;
}
0