답안 #589658

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
589658 2022-07-05T05:27:47 Z 박상훈(#8406) 놀이터에 떨어진 이상한 약 (FXCUP3_gorgeous) C++14
100 / 100
730 ms 169232 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
struct Seg{
    ll tree[600600], sz;
    void init(int n){sz = n;}
    void update(int p, ll x){
        p += sz;
        for (tree[p] = max(tree[p], x);p>1;p>>=1) tree[p>>1] = max(tree[p], tree[p^1]);
    }
    ll query(int l, int r){
        ++r;
        ll ret = 0;
        for (l+=sz, r+=sz;l<r;l>>=1, r>>=1){
            if (l&1) ret = max(ret, tree[l++]);
            if (r&1) ret = max(ret, tree[--r]);
        }
        return ret;
    }
}tree;
map<int, ll> dp[300300];
int a[300300], c[300300], n;

int f(int i, int t){
    if (i>n || i<1) return 0;
    if (c[i]==t) return a[i];
    return 0;
}

bool valid(int x, int y){
    if (x>y) return 0;
    if (y>n) return 0;
    if (x<1) return 0;
    return 1;
}

bool cmp(pair<int, int> a, pair<int, int> b){
    if (a.first==b.first) return a.second > b.second;
    return a.first < b.first;
}

int main(){
    scanf("%d", &n);

    vector<pair<int, int>> P;
    for (int i=1;i<=n;i++){
        scanf("%d", c+i);

        P.emplace_back(i, i+c[i]-1);
        P.emplace_back(i+1, i+c[i]-1);
        P.emplace_back(i-c[i]+1, i);
        P.emplace_back(i-c[i]+1, i-1);

        P.emplace_back(i, i);
    }
    for (int i=1;i<=n;i++) scanf("%d", a+i);

    sort(P.begin(), P.end(), cmp);
    P.erase(unique(P.begin(), P.end()), P.end());
    tree.init(n+1);

    for (auto [i, j]:P) if (valid(i, j)){
        ll &ret = dp[i][j];
        ret = tree.query(j, n);
        ret = max(ret, dp[i-1][j] + f(i-1, j-i+2));
        ret = max(ret, dp[i][j+1] + f(j+1, j-i+2));

        tree.update(j, ret);
    }

    for (int i=1;i<=n;i++) printf("%lld ", dp[i][i] + f(i, 1));
    return 0;
}

Compilation message

gorgeous.cpp: In function 'int main()':
gorgeous.cpp:63:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   63 |     for (auto [i, j]:P) if (valid(i, j)){
      |               ^
gorgeous.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
gorgeous.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         scanf("%d", c+i);
      |         ~~~~~^~~~~~~~~~~
gorgeous.cpp:57:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |     for (int i=1;i<=n;i++) scanf("%d", a+i);
      |                            ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 9 ms 14372 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 9 ms 14420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 9 ms 14372 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 9 ms 14420 KB Output is correct
7 Correct 8 ms 14420 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 9 ms 14548 KB Output is correct
11 Correct 9 ms 14804 KB Output is correct
12 Correct 9 ms 14804 KB Output is correct
13 Correct 9 ms 14952 KB Output is correct
14 Correct 10 ms 14968 KB Output is correct
15 Correct 9 ms 14932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 9 ms 14372 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 9 ms 14420 KB Output is correct
7 Correct 8 ms 14420 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 9 ms 14548 KB Output is correct
11 Correct 9 ms 14804 KB Output is correct
12 Correct 9 ms 14804 KB Output is correct
13 Correct 9 ms 14952 KB Output is correct
14 Correct 10 ms 14968 KB Output is correct
15 Correct 9 ms 14932 KB Output is correct
16 Correct 19 ms 17016 KB Output is correct
17 Correct 69 ms 26648 KB Output is correct
18 Correct 224 ms 63628 KB Output is correct
19 Correct 322 ms 78348 KB Output is correct
20 Correct 682 ms 161884 KB Output is correct
21 Correct 633 ms 169232 KB Output is correct
22 Correct 663 ms 169140 KB Output is correct
23 Correct 730 ms 168672 KB Output is correct
24 Correct 649 ms 169208 KB Output is correct
25 Correct 673 ms 160636 KB Output is correct