답안 #285009

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
285009 2020-08-28T08:52:20 Z achibasadzishvili Discharging (NOI20_discharging) C++17
13 / 100
1000 ms 161040 KB
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
int n,a[1000002];
ll dp[1000002];
int rm[1000002][21],po[2000002],pw[200],raod,mn,lo;
int lef[1000002],rig[1000002];
vector<int>del[1000002];
int get(int x,int y){
    if(rm[y][po[y - x + 1]] > rm[x + pw[po[y - x + 1]] - 1][lo])return rm[y][po[y - x + 1]];
    return rm[x + pw[po[y - x + 1]] - 1][po[y - x + 1]];
}
int ind(int x,int y){
    if(y == n)return -1;
    ll l = y + 1,r = n,mid,ind = -1;
    while(r >= l){
        mid = (l + r) / 2;
        if(dp[x] + (ll)get(x + 1 , mid) * (n - x) > dp[y] + (ll)get(y + 1 , mid) * (n - y)){
            r = mid - 1;
            ind = mid;
        }
        else
            l = mid + 1;
    }
    return ind;
}
void delet(int x){
    if(lef[x] == rig[x] && lef[x] == -1)return;
    if(lef[x] == -1){
        lef[rig[x]] = -1;
        mn = rig[x];
        rig[x] = -1;
        return;
    }
    rig[lef[x]] = rig[x];
    lef[rig[x]] = lef[x];
    int cur = ind(lef[x] , rig[x]);
    if(cur == -1){
        lef[x] = rig[x] = -1;
        return;
    }
    del[cur].pb(lef[x]);
    lef[x] = rig[x] = -1;
}
int main(){
    scanf("%d",&n);
    for(int i=1; i<=n; i++){
        scanf("%d",&a[i]);
    }
    //int cl = clock();
    //n = 1000000;
    //for(int i=1; i<=n; i++)
    //    a[i] = n-i+1;
    pw[0] = 1;
    
    for(int i=1; i<=21; i++){
        pw[i] = pw[i - 1] * 2;
        for(int j=pw[i - 1]; j<pw[i]; j++){
            if(j <= 1000000)
                po[j] = i - 1;
        }
    }
    for(int i=0; i<=n; i++)
        lef[i] = rig[i] = -1;
    for(int i=1; i<=n; i++){
        rm[i][0] = a[i];
        for(int j=1; j<=19; j++){
            rm[i][j] = rm[i][j - 1];
            if(i - pw[j] + 1 >= 1 && rm[i - pw[j - 1]][j - 1]>rm[i][j])
                rm[i][j] = rm[i - pw[j - 1]][j - 1];
        }
    }
    //cout << clock() - cl << '\n';
    for(int i=1; i<=n; i++){
        for(int j=0; j<del[i].size(); j++){
            delet(del[i][j]);
        }
        dp[i] = dp[mn] + (ll)get(mn + 1 , i) * (ll)(n - mn);
        rig[i - 1] = i;
        lef[i] = i - 1;
        ll cur = ind(i - 1 , i);
        if(cur != -1)
            del[cur].pb(i - 1);
    }
    //cout << "time: " << clock() - cl << " " << raod << '\n';
    cout << dp[n];
    
    
    return 0;
}

Compilation message

Discharging.cpp: In function 'int main()':
Discharging.cpp:78:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |         for(int j=0; j<del[i].size(); j++){
      |                      ~^~~~~~~~~~~~~~
Discharging.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   49 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
Discharging.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 27776 KB Output is correct
2 Correct 19 ms 27776 KB Output is correct
3 Correct 19 ms 27776 KB Output is correct
4 Correct 18 ms 27776 KB Output is correct
5 Correct 18 ms 27776 KB Output is correct
6 Correct 27 ms 27776 KB Output is correct
7 Correct 19 ms 27776 KB Output is correct
8 Correct 20 ms 27776 KB Output is correct
9 Correct 18 ms 27776 KB Output is correct
10 Correct 19 ms 27776 KB Output is correct
11 Correct 19 ms 27724 KB Output is correct
12 Incorrect 18 ms 27776 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 27904 KB Output is correct
2 Correct 19 ms 27904 KB Output is correct
3 Correct 21 ms 27940 KB Output is correct
4 Correct 21 ms 27936 KB Output is correct
5 Correct 21 ms 27904 KB Output is correct
6 Correct 21 ms 27904 KB Output is correct
7 Correct 20 ms 27904 KB Output is correct
8 Correct 21 ms 27904 KB Output is correct
9 Correct 30 ms 27896 KB Output is correct
10 Correct 18 ms 27904 KB Output is correct
11 Correct 21 ms 27904 KB Output is correct
12 Correct 19 ms 27904 KB Output is correct
13 Correct 19 ms 27904 KB Output is correct
14 Correct 28 ms 27904 KB Output is correct
15 Correct 22 ms 27904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 27904 KB Output is correct
2 Correct 19 ms 27904 KB Output is correct
3 Correct 21 ms 27940 KB Output is correct
4 Correct 21 ms 27936 KB Output is correct
5 Correct 21 ms 27904 KB Output is correct
6 Correct 21 ms 27904 KB Output is correct
7 Correct 20 ms 27904 KB Output is correct
8 Correct 21 ms 27904 KB Output is correct
9 Correct 30 ms 27896 KB Output is correct
10 Correct 18 ms 27904 KB Output is correct
11 Correct 21 ms 27904 KB Output is correct
12 Correct 19 ms 27904 KB Output is correct
13 Correct 19 ms 27904 KB Output is correct
14 Correct 28 ms 27904 KB Output is correct
15 Correct 22 ms 27904 KB Output is correct
16 Execution timed out 1099 ms 150528 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1051 ms 161040 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 27776 KB Output is correct
2 Correct 19 ms 27776 KB Output is correct
3 Correct 19 ms 27776 KB Output is correct
4 Correct 18 ms 27776 KB Output is correct
5 Correct 18 ms 27776 KB Output is correct
6 Correct 27 ms 27776 KB Output is correct
7 Correct 19 ms 27776 KB Output is correct
8 Correct 20 ms 27776 KB Output is correct
9 Correct 18 ms 27776 KB Output is correct
10 Correct 19 ms 27776 KB Output is correct
11 Correct 19 ms 27724 KB Output is correct
12 Incorrect 18 ms 27776 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 27776 KB Output is correct
2 Correct 19 ms 27776 KB Output is correct
3 Correct 19 ms 27776 KB Output is correct
4 Correct 18 ms 27776 KB Output is correct
5 Correct 18 ms 27776 KB Output is correct
6 Correct 27 ms 27776 KB Output is correct
7 Correct 19 ms 27776 KB Output is correct
8 Correct 20 ms 27776 KB Output is correct
9 Correct 18 ms 27776 KB Output is correct
10 Correct 19 ms 27776 KB Output is correct
11 Correct 19 ms 27724 KB Output is correct
12 Incorrect 18 ms 27776 KB Output isn't correct
13 Halted 0 ms 0 KB -