답안 #861665

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
861665 2023-10-16T15:57:05 Z nnhzzz K개의 묶음 (IZhO14_blocks) C++14
100 / 100
119 ms 42212 KB
// cre: Nguyen Ngoc Hung - Train VOI 2024

#include<bits/stdc++.h>

using namespace std;

#define        __nnhzzz__  signed main()
#define          BIT(i,j)  ((i>>j)&1LL)
#define           MASK(i)  (1LL<<i)
#define            ALL(x)  (x).begin(),(x).end()
#define             SZ(x)  (int)(x).size()
#define                fi  first
#define                se  second
#define                ll  long long
#define               ull  unsigned long long
#define                ld  long double
#define                vi  vector<int>
#define               vvi  vector<vi>
#define              vvvi  vector<vvi>
#define               pii  pair<int,int>
#define              vpii  vector<pii>
#define        REP(i,a,b)  for(int i = (a); i<=(b); ++i)
#define       REPD(i,a,b)  for(int i = (a); i>=(b); --i)
#define   REPDIS(i,a,b,c)  for(int i = (a); i<=(b); i+=c)

//-------------------------------------------------------------//
const int inf = 1e9,LOG = 20,MAXN = 1e5+7,N = 1e2+3;
const int MOD = 1e9+7,MOD1 = 1e9+207,MOD2 = 1e9+407,MOD3 = 998244353;
//-------------------------------------------------------------//
template<typename T1, typename T2> bool mini(T1 &a, T2 b){if(a>b){a=b;return true;}return false;}
template<typename T1, typename T2> bool maxi(T1 &a, T2 b){if(a<b){a=b;return true;}return false;}

/*
----------------------------------------------------------------
    END OF TEMPLATE
----------------------------------------------------------------
    Nguyen Ngoc Hung - nnhzzz
    Training for VOI24 gold medal
----------------------------------------------------------------
*/

int a[MAXN],dp[MAXN][102],l[MAXN],f[MAXN];

void solve(){
    int n,k; cin >> n >> k;
    memset(dp,0x3f,sizeof dp);
    dp[0][1] = 0;
    REP(i,1,n){
        cin >> a[i];
        dp[i][1] = max(dp[i-1][1],a[i]);
    }
    REP(i,1,n) for(l[i] = i-1; l[i] && a[l[i]]<=a[i]; ) l[i] = l[l[i]];
    REP(i,2,k){
        f[i-1] = inf;
        REP(j,i,n){
            f[j] = dp[j-1][i-1];
            for(int t = j-1; t>l[j]; t = l[t]) mini(f[j],f[t]);
            dp[j][i] = min(dp[l[j]][i],f[j]+a[j]);
        }
    }
    cout << dp[n][k];
}

__nnhzzz__{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #define name "test"
    if(fopen(name".inp","r")){
        freopen(name".inp","r",stdin);
        freopen(name".out","w",stdout);
    }
    #define name1 "nnhzzz"
    if(fopen(name1".inp","r")){
        freopen(name1".inp","r",stdin);
        freopen(name1".out","w",stdout);
    }
    int test = 1;
    while(test--){
        solve();
    }
    cerr << "\nTime elapsed: " << 1000*clock()/CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         freopen(name".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen(name".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         freopen(name1".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen(name1".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 40796 KB Output is correct
2 Correct 6 ms 40796 KB Output is correct
3 Correct 5 ms 40996 KB Output is correct
4 Correct 5 ms 40916 KB Output is correct
5 Correct 5 ms 40792 KB Output is correct
6 Correct 5 ms 40796 KB Output is correct
7 Correct 5 ms 40956 KB Output is correct
8 Correct 5 ms 40792 KB Output is correct
9 Correct 6 ms 40792 KB Output is correct
10 Correct 5 ms 40792 KB Output is correct
11 Correct 5 ms 40792 KB Output is correct
12 Correct 5 ms 40792 KB Output is correct
13 Correct 6 ms 41052 KB Output is correct
14 Correct 5 ms 40792 KB Output is correct
15 Correct 5 ms 40796 KB Output is correct
16 Correct 5 ms 40920 KB Output is correct
17 Correct 5 ms 40808 KB Output is correct
18 Correct 5 ms 40980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 40796 KB Output is correct
2 Correct 5 ms 40960 KB Output is correct
3 Correct 5 ms 40796 KB Output is correct
4 Correct 5 ms 40792 KB Output is correct
5 Correct 6 ms 40796 KB Output is correct
6 Correct 5 ms 40796 KB Output is correct
7 Correct 5 ms 40796 KB Output is correct
8 Correct 5 ms 40796 KB Output is correct
9 Correct 5 ms 40796 KB Output is correct
10 Correct 5 ms 40796 KB Output is correct
11 Correct 5 ms 40792 KB Output is correct
12 Correct 5 ms 40924 KB Output is correct
13 Correct 5 ms 40968 KB Output is correct
14 Correct 5 ms 40796 KB Output is correct
15 Correct 6 ms 40796 KB Output is correct
16 Correct 5 ms 40796 KB Output is correct
17 Correct 5 ms 40952 KB Output is correct
18 Correct 5 ms 41048 KB Output is correct
19 Correct 5 ms 40796 KB Output is correct
20 Correct 5 ms 40796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 40796 KB Output is correct
2 Correct 6 ms 40796 KB Output is correct
3 Correct 5 ms 40996 KB Output is correct
4 Correct 5 ms 40916 KB Output is correct
5 Correct 5 ms 40792 KB Output is correct
6 Correct 5 ms 40796 KB Output is correct
7 Correct 5 ms 40956 KB Output is correct
8 Correct 5 ms 40792 KB Output is correct
9 Correct 6 ms 40792 KB Output is correct
10 Correct 5 ms 40792 KB Output is correct
11 Correct 5 ms 40792 KB Output is correct
12 Correct 5 ms 40792 KB Output is correct
13 Correct 6 ms 41052 KB Output is correct
14 Correct 5 ms 40792 KB Output is correct
15 Correct 5 ms 40796 KB Output is correct
16 Correct 5 ms 40920 KB Output is correct
17 Correct 5 ms 40808 KB Output is correct
18 Correct 5 ms 40980 KB Output is correct
19 Correct 5 ms 40796 KB Output is correct
20 Correct 5 ms 40960 KB Output is correct
21 Correct 5 ms 40796 KB Output is correct
22 Correct 5 ms 40792 KB Output is correct
23 Correct 6 ms 40796 KB Output is correct
24 Correct 5 ms 40796 KB Output is correct
25 Correct 5 ms 40796 KB Output is correct
26 Correct 5 ms 40796 KB Output is correct
27 Correct 5 ms 40796 KB Output is correct
28 Correct 5 ms 40796 KB Output is correct
29 Correct 5 ms 40792 KB Output is correct
30 Correct 5 ms 40924 KB Output is correct
31 Correct 5 ms 40968 KB Output is correct
32 Correct 5 ms 40796 KB Output is correct
33 Correct 6 ms 40796 KB Output is correct
34 Correct 5 ms 40796 KB Output is correct
35 Correct 5 ms 40952 KB Output is correct
36 Correct 5 ms 41048 KB Output is correct
37 Correct 5 ms 40796 KB Output is correct
38 Correct 5 ms 40796 KB Output is correct
39 Correct 5 ms 40792 KB Output is correct
40 Correct 5 ms 40796 KB Output is correct
41 Correct 5 ms 40796 KB Output is correct
42 Correct 6 ms 40796 KB Output is correct
43 Correct 6 ms 40796 KB Output is correct
44 Correct 5 ms 40792 KB Output is correct
45 Correct 5 ms 40796 KB Output is correct
46 Correct 5 ms 40796 KB Output is correct
47 Correct 6 ms 40796 KB Output is correct
48 Correct 6 ms 40796 KB Output is correct
49 Correct 6 ms 40792 KB Output is correct
50 Correct 5 ms 40796 KB Output is correct
51 Correct 5 ms 40984 KB Output is correct
52 Correct 5 ms 40796 KB Output is correct
53 Correct 5 ms 40796 KB Output is correct
54 Correct 5 ms 40924 KB Output is correct
55 Correct 5 ms 40796 KB Output is correct
56 Correct 5 ms 40796 KB Output is correct
57 Correct 5 ms 40792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 40796 KB Output is correct
2 Correct 6 ms 40796 KB Output is correct
3 Correct 5 ms 40996 KB Output is correct
4 Correct 5 ms 40916 KB Output is correct
5 Correct 5 ms 40792 KB Output is correct
6 Correct 5 ms 40796 KB Output is correct
7 Correct 5 ms 40956 KB Output is correct
8 Correct 5 ms 40792 KB Output is correct
9 Correct 6 ms 40792 KB Output is correct
10 Correct 5 ms 40792 KB Output is correct
11 Correct 5 ms 40792 KB Output is correct
12 Correct 5 ms 40792 KB Output is correct
13 Correct 6 ms 41052 KB Output is correct
14 Correct 5 ms 40792 KB Output is correct
15 Correct 5 ms 40796 KB Output is correct
16 Correct 5 ms 40920 KB Output is correct
17 Correct 5 ms 40808 KB Output is correct
18 Correct 5 ms 40980 KB Output is correct
19 Correct 5 ms 40796 KB Output is correct
20 Correct 5 ms 40960 KB Output is correct
21 Correct 5 ms 40796 KB Output is correct
22 Correct 5 ms 40792 KB Output is correct
23 Correct 6 ms 40796 KB Output is correct
24 Correct 5 ms 40796 KB Output is correct
25 Correct 5 ms 40796 KB Output is correct
26 Correct 5 ms 40796 KB Output is correct
27 Correct 5 ms 40796 KB Output is correct
28 Correct 5 ms 40796 KB Output is correct
29 Correct 5 ms 40792 KB Output is correct
30 Correct 5 ms 40924 KB Output is correct
31 Correct 5 ms 40968 KB Output is correct
32 Correct 5 ms 40796 KB Output is correct
33 Correct 6 ms 40796 KB Output is correct
34 Correct 5 ms 40796 KB Output is correct
35 Correct 5 ms 40952 KB Output is correct
36 Correct 5 ms 41048 KB Output is correct
37 Correct 5 ms 40796 KB Output is correct
38 Correct 5 ms 40796 KB Output is correct
39 Correct 5 ms 40792 KB Output is correct
40 Correct 5 ms 40796 KB Output is correct
41 Correct 5 ms 40796 KB Output is correct
42 Correct 6 ms 40796 KB Output is correct
43 Correct 6 ms 40796 KB Output is correct
44 Correct 5 ms 40792 KB Output is correct
45 Correct 5 ms 40796 KB Output is correct
46 Correct 5 ms 40796 KB Output is correct
47 Correct 6 ms 40796 KB Output is correct
48 Correct 6 ms 40796 KB Output is correct
49 Correct 6 ms 40792 KB Output is correct
50 Correct 5 ms 40796 KB Output is correct
51 Correct 5 ms 40984 KB Output is correct
52 Correct 5 ms 40796 KB Output is correct
53 Correct 5 ms 40796 KB Output is correct
54 Correct 5 ms 40924 KB Output is correct
55 Correct 5 ms 40796 KB Output is correct
56 Correct 5 ms 40796 KB Output is correct
57 Correct 5 ms 40792 KB Output is correct
58 Correct 8 ms 41052 KB Output is correct
59 Correct 8 ms 41308 KB Output is correct
60 Correct 10 ms 41564 KB Output is correct
61 Correct 30 ms 41564 KB Output is correct
62 Correct 77 ms 42212 KB Output is correct
63 Correct 13 ms 42076 KB Output is correct
64 Correct 42 ms 42068 KB Output is correct
65 Correct 6 ms 40796 KB Output is correct
66 Correct 5 ms 40796 KB Output is correct
67 Correct 5 ms 40796 KB Output is correct
68 Correct 5 ms 40796 KB Output is correct
69 Correct 5 ms 40792 KB Output is correct
70 Correct 5 ms 41048 KB Output is correct
71 Correct 15 ms 40964 KB Output is correct
72 Correct 6 ms 41052 KB Output is correct
73 Correct 9 ms 41052 KB Output is correct
74 Correct 9 ms 41268 KB Output is correct
75 Correct 11 ms 41560 KB Output is correct
76 Correct 41 ms 41504 KB Output is correct
77 Correct 119 ms 42204 KB Output is correct
78 Correct 15 ms 42076 KB Output is correct
79 Correct 61 ms 42076 KB Output is correct
80 Correct 13 ms 41820 KB Output is correct
81 Correct 21 ms 42076 KB Output is correct
82 Correct 112 ms 42076 KB Output is correct
83 Correct 5 ms 40796 KB Output is correct
84 Correct 5 ms 40920 KB Output is correct
85 Correct 12 ms 41048 KB Output is correct
86 Correct 7 ms 41052 KB Output is correct
87 Correct 8 ms 41048 KB Output is correct
88 Correct 8 ms 41308 KB Output is correct
89 Correct 10 ms 41584 KB Output is correct
90 Correct 31 ms 41560 KB Output is correct
91 Correct 79 ms 42072 KB Output is correct
92 Correct 14 ms 42076 KB Output is correct
93 Correct 41 ms 42072 KB Output is correct
94 Correct 7 ms 41308 KB Output is correct
95 Correct 11 ms 41048 KB Output is correct
96 Correct 5 ms 40912 KB Output is correct
97 Correct 5 ms 40796 KB Output is correct
98 Correct 5 ms 40796 KB Output is correct
99 Correct 6 ms 40796 KB Output is correct