이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// In the name of GOD
#include <bits/stdc++.h>
using namespace std;
#define BeGood ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define nl '\n'
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
typedef long long ll;
typedef double db;
const int N = 1e5 + 101;
const ll M = 1e13 + 7;
int n, k;
int a[N];
map<pair<int, int>, int> m;
long long man(int id, int al){
if(al < 0){
m[{id, al}] = M;
return M;
}
if(id > n){
if(al == 0){
m[{id, al}] = 1;
return 0;
}
m[{id, al}] = M;
return M;
}
if(m[{id, al}] > 0){
return m[{id, al}] - 1;
}
long long ans = M;
int mx = 0;
for(int i = id; i <= n; ++i){
mx = max(mx, a[i]);
ans = min(ans, man(i + 1, al - 1) + mx);
}
return ans;
}
int main(){
BeGood
cin >> n >> k;
for(int i = 1; i <= n; ++i){
cin >> a[i];
}
cout << man(1, k);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
blocks.cpp: In function 'long long int man(int, int)':
blocks.cpp:27:25: warning: overflow in implicit constant conversion [-Woverflow]
m[{id, al}] = M;
^
blocks.cpp:35:25: warning: overflow in implicit constant conversion [-Woverflow]
m[{id, al}] = M;
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |