답안 #1101543

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1101543 2024-10-16T09:47:08 Z thanhhoang K개의 묶음 (IZhO14_blocks) C++14
100 / 100
277 ms 49548 KB
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+53;
int n,k,a[N],b[102][N],c[N],e[N],f[N][20];
stack<int>d;
void build(int oo)
{
    for(int i=0;i<=n;i++) f[i][0]=b[oo][i];
    for(int i=1;(1 << i) <= n;i++)
        for(int j=0;j+(1<<i)-1<=n;j++)
            f[j][i]=min(f[j][i-1],f[j+(1<<i-1)][i-1]);
}
int get(int l,int r)
{
    if (l > r) return 1e9;
    int o=__lg(r-l+1);
    return min(f[l][o],f[r-(1<<o)+1][o]);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if(fopen("cc.inp","r"))
    {
        freopen("cc.inp","r",stdin);
        freopen("cc.out","w",stdout);
    }
    cin>>n>>k;
    a[0]=1e9;
    d.push(0);
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        while(a[d.top()]<=a[i]) d.pop();
        c[i]=d.top();
        d.push(i);
    }
    memset(b,0x3f,sizeof b);
    b[0][0]=0;
    for(int i=1;i<=k;i++)
    {
        build(i-1);
        for(int j=1;j<=n;j++)
            b[i][j]=min(b[i][c[j]],get(c[j],j-1)+a[j]);
    }

    cout<<b[k][n];
    return 0;
}

Compilation message

blocks.cpp: In function 'void build(int)':
blocks.cpp:11:44: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   11 |             f[j][i]=min(f[j][i-1],f[j+(1<<i-1)][i-1]);
      |                                           ~^~
blocks.cpp: In function 'int main()':
blocks.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen("cc.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
blocks.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen("cc.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 42576 KB Output is correct
2 Correct 6 ms 42576 KB Output is correct
3 Correct 7 ms 42576 KB Output is correct
4 Correct 6 ms 42576 KB Output is correct
5 Correct 6 ms 42576 KB Output is correct
6 Correct 6 ms 42496 KB Output is correct
7 Correct 7 ms 42576 KB Output is correct
8 Correct 6 ms 42576 KB Output is correct
9 Correct 6 ms 42476 KB Output is correct
10 Correct 6 ms 42576 KB Output is correct
11 Correct 6 ms 42576 KB Output is correct
12 Correct 6 ms 42576 KB Output is correct
13 Correct 6 ms 42576 KB Output is correct
14 Correct 7 ms 42576 KB Output is correct
15 Correct 6 ms 42576 KB Output is correct
16 Correct 7 ms 42576 KB Output is correct
17 Correct 6 ms 42520 KB Output is correct
18 Correct 6 ms 42576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 42576 KB Output is correct
2 Correct 6 ms 42576 KB Output is correct
3 Correct 7 ms 42576 KB Output is correct
4 Correct 6 ms 42576 KB Output is correct
5 Correct 6 ms 42488 KB Output is correct
6 Correct 6 ms 42576 KB Output is correct
7 Correct 6 ms 42576 KB Output is correct
8 Correct 6 ms 42576 KB Output is correct
9 Correct 6 ms 42576 KB Output is correct
10 Correct 7 ms 42640 KB Output is correct
11 Correct 8 ms 42576 KB Output is correct
12 Correct 8 ms 42576 KB Output is correct
13 Correct 6 ms 42576 KB Output is correct
14 Correct 6 ms 42576 KB Output is correct
15 Correct 6 ms 42576 KB Output is correct
16 Correct 7 ms 42748 KB Output is correct
17 Correct 7 ms 42576 KB Output is correct
18 Correct 7 ms 42576 KB Output is correct
19 Correct 7 ms 42576 KB Output is correct
20 Correct 6 ms 42476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 42576 KB Output is correct
2 Correct 6 ms 42576 KB Output is correct
3 Correct 7 ms 42576 KB Output is correct
4 Correct 6 ms 42576 KB Output is correct
5 Correct 6 ms 42576 KB Output is correct
6 Correct 6 ms 42496 KB Output is correct
7 Correct 7 ms 42576 KB Output is correct
8 Correct 6 ms 42576 KB Output is correct
9 Correct 6 ms 42476 KB Output is correct
10 Correct 6 ms 42576 KB Output is correct
11 Correct 6 ms 42576 KB Output is correct
12 Correct 6 ms 42576 KB Output is correct
13 Correct 6 ms 42576 KB Output is correct
14 Correct 7 ms 42576 KB Output is correct
15 Correct 6 ms 42576 KB Output is correct
16 Correct 7 ms 42576 KB Output is correct
17 Correct 6 ms 42520 KB Output is correct
18 Correct 6 ms 42576 KB Output is correct
19 Correct 6 ms 42576 KB Output is correct
20 Correct 6 ms 42576 KB Output is correct
21 Correct 7 ms 42576 KB Output is correct
22 Correct 6 ms 42576 KB Output is correct
23 Correct 6 ms 42488 KB Output is correct
24 Correct 6 ms 42576 KB Output is correct
25 Correct 6 ms 42576 KB Output is correct
26 Correct 6 ms 42576 KB Output is correct
27 Correct 6 ms 42576 KB Output is correct
28 Correct 7 ms 42640 KB Output is correct
29 Correct 8 ms 42576 KB Output is correct
30 Correct 8 ms 42576 KB Output is correct
31 Correct 6 ms 42576 KB Output is correct
32 Correct 6 ms 42576 KB Output is correct
33 Correct 6 ms 42576 KB Output is correct
34 Correct 7 ms 42748 KB Output is correct
35 Correct 7 ms 42576 KB Output is correct
36 Correct 7 ms 42576 KB Output is correct
37 Correct 7 ms 42576 KB Output is correct
38 Correct 6 ms 42476 KB Output is correct
39 Correct 6 ms 42744 KB Output is correct
40 Correct 6 ms 42488 KB Output is correct
41 Correct 6 ms 42576 KB Output is correct
42 Correct 6 ms 42576 KB Output is correct
43 Correct 5 ms 42576 KB Output is correct
44 Correct 6 ms 42628 KB Output is correct
45 Correct 6 ms 42576 KB Output is correct
46 Correct 6 ms 42576 KB Output is correct
47 Correct 6 ms 42592 KB Output is correct
48 Correct 6 ms 42576 KB Output is correct
49 Correct 6 ms 42576 KB Output is correct
50 Correct 7 ms 42576 KB Output is correct
51 Correct 6 ms 42576 KB Output is correct
52 Correct 6 ms 42576 KB Output is correct
53 Correct 6 ms 42576 KB Output is correct
54 Correct 6 ms 42448 KB Output is correct
55 Correct 6 ms 42588 KB Output is correct
56 Correct 5 ms 42576 KB Output is correct
57 Correct 7 ms 42576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 42576 KB Output is correct
2 Correct 6 ms 42576 KB Output is correct
3 Correct 7 ms 42576 KB Output is correct
4 Correct 6 ms 42576 KB Output is correct
5 Correct 6 ms 42576 KB Output is correct
6 Correct 6 ms 42496 KB Output is correct
7 Correct 7 ms 42576 KB Output is correct
8 Correct 6 ms 42576 KB Output is correct
9 Correct 6 ms 42476 KB Output is correct
10 Correct 6 ms 42576 KB Output is correct
11 Correct 6 ms 42576 KB Output is correct
12 Correct 6 ms 42576 KB Output is correct
13 Correct 6 ms 42576 KB Output is correct
14 Correct 7 ms 42576 KB Output is correct
15 Correct 6 ms 42576 KB Output is correct
16 Correct 7 ms 42576 KB Output is correct
17 Correct 6 ms 42520 KB Output is correct
18 Correct 6 ms 42576 KB Output is correct
19 Correct 6 ms 42576 KB Output is correct
20 Correct 6 ms 42576 KB Output is correct
21 Correct 7 ms 42576 KB Output is correct
22 Correct 6 ms 42576 KB Output is correct
23 Correct 6 ms 42488 KB Output is correct
24 Correct 6 ms 42576 KB Output is correct
25 Correct 6 ms 42576 KB Output is correct
26 Correct 6 ms 42576 KB Output is correct
27 Correct 6 ms 42576 KB Output is correct
28 Correct 7 ms 42640 KB Output is correct
29 Correct 8 ms 42576 KB Output is correct
30 Correct 8 ms 42576 KB Output is correct
31 Correct 6 ms 42576 KB Output is correct
32 Correct 6 ms 42576 KB Output is correct
33 Correct 6 ms 42576 KB Output is correct
34 Correct 7 ms 42748 KB Output is correct
35 Correct 7 ms 42576 KB Output is correct
36 Correct 7 ms 42576 KB Output is correct
37 Correct 7 ms 42576 KB Output is correct
38 Correct 6 ms 42476 KB Output is correct
39 Correct 6 ms 42744 KB Output is correct
40 Correct 6 ms 42488 KB Output is correct
41 Correct 6 ms 42576 KB Output is correct
42 Correct 6 ms 42576 KB Output is correct
43 Correct 5 ms 42576 KB Output is correct
44 Correct 6 ms 42628 KB Output is correct
45 Correct 6 ms 42576 KB Output is correct
46 Correct 6 ms 42576 KB Output is correct
47 Correct 6 ms 42592 KB Output is correct
48 Correct 6 ms 42576 KB Output is correct
49 Correct 6 ms 42576 KB Output is correct
50 Correct 7 ms 42576 KB Output is correct
51 Correct 6 ms 42576 KB Output is correct
52 Correct 6 ms 42576 KB Output is correct
53 Correct 6 ms 42576 KB Output is correct
54 Correct 6 ms 42448 KB Output is correct
55 Correct 6 ms 42588 KB Output is correct
56 Correct 5 ms 42576 KB Output is correct
57 Correct 7 ms 42576 KB Output is correct
58 Correct 15 ms 44880 KB Output is correct
59 Correct 10 ms 46928 KB Output is correct
60 Correct 18 ms 47148 KB Output is correct
61 Correct 91 ms 47100 KB Output is correct
62 Correct 265 ms 49232 KB Output is correct
63 Correct 22 ms 49232 KB Output is correct
64 Correct 126 ms 49232 KB Output is correct
65 Correct 6 ms 42576 KB Output is correct
66 Correct 5 ms 42576 KB Output is correct
67 Correct 6 ms 42576 KB Output is correct
68 Correct 6 ms 42576 KB Output is correct
69 Correct 6 ms 42576 KB Output is correct
70 Correct 6 ms 42740 KB Output is correct
71 Correct 25 ms 44880 KB Output is correct
72 Correct 7 ms 44880 KB Output is correct
73 Correct 13 ms 44880 KB Output is correct
74 Correct 10 ms 47096 KB Output is correct
75 Correct 18 ms 46944 KB Output is correct
76 Correct 84 ms 46928 KB Output is correct
77 Correct 273 ms 49232 KB Output is correct
78 Correct 21 ms 49232 KB Output is correct
79 Correct 125 ms 49396 KB Output is correct
80 Correct 17 ms 49320 KB Output is correct
81 Correct 39 ms 49232 KB Output is correct
82 Correct 260 ms 49400 KB Output is correct
83 Correct 6 ms 42576 KB Output is correct
84 Correct 7 ms 42548 KB Output is correct
85 Correct 28 ms 44968 KB Output is correct
86 Correct 7 ms 44880 KB Output is correct
87 Correct 13 ms 44880 KB Output is correct
88 Correct 12 ms 47184 KB Output is correct
89 Correct 19 ms 47184 KB Output is correct
90 Correct 104 ms 47084 KB Output is correct
91 Correct 277 ms 49488 KB Output is correct
92 Correct 23 ms 49488 KB Output is correct
93 Correct 152 ms 49548 KB Output is correct
94 Correct 7 ms 45048 KB Output is correct
95 Correct 26 ms 44880 KB Output is correct
96 Correct 6 ms 42576 KB Output is correct
97 Correct 6 ms 42576 KB Output is correct
98 Correct 6 ms 42576 KB Output is correct
99 Correct 6 ms 42576 KB Output is correct