길이 n의 숫자 배열이 주어질 때


A[i] <= A[i-1]*2 꼴이 연속해서 나타나는 가장 긴 길이를 출력하는 문제다.


배열 선언 안했어도 됐는데 메모리 낭비 해버렸다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <algorithm>
using namespace std;
 
int n, ans;
int a[200001];
int d[200001];
 
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        d[i] = 1;
        if (i - 1 >= 0 && a[i - 1* 2 >= a[i])
            d[i] = d[i - 1+ 1;
        ans = max(ans, d[i]);
    }
    cout << ans;
    return 0;
}
cs


'codeforces > #506 div3' 카테고리의 다른 글

F. Multicolored Markers  (0) 2018.08.29
D. Concatenated Multiples  (0) 2018.08.29
C. Maximal Intersection  (0) 2018.08.29
A. Many Equal Substrings  (0) 2018.08.29

+ Recent posts