답안 #1014455

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1014455 2024-07-04T22:18:13 Z rayan_bd Stove (JOI18_stove) C++17
20 / 100
1000 ms 196664 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; 


#define getar(ar,n) for(ll i=0;i<n;++i) cin>>ar[i]
#define show(n) cout<<n<<'\n'
#define all(v) v.begin(), v.end()
#define br cout<<"\n"
#define pb push_back
#define nl '\n'
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define ret return
#define ll long long
#define ld long double
#define sza(x) ((int)x.size())

const int mxN = 5005;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ld EPS = 1e-9;

ll ar[mxN];
ll dp[mxN][mxN];
ll n;

ll f(ll idx,ll prev,ll k){
	if(idx==n) return 0;
	if(k<=0) return INF;
	//if(dp[idx][k]!=-1) return dp[idx][k];
	ll cut=ar[idx]+1-prev+f(idx+1,ar[idx+1],k-1);
	ll notCut=f(idx+1,prev,k);
	if(idx==n-1){
		notCut+=ar[idx]+1-prev;
	}
	return dp[idx][k]=min(cut,notCut);
}

void solve(ll tc) {
    ll k;cin>>n>>k;
    memset(dp,-1,sizeof(dp));
    getar(ar,n);
    sort(ar,ar+n);
    cout<<f(0,ar[0],k)<<nl;
}

int main() {
    


    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    solve(0);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 196432 KB Output is correct
2 Correct 81 ms 196480 KB Output is correct
3 Correct 99 ms 196284 KB Output is correct
4 Correct 81 ms 196432 KB Output is correct
5 Correct 80 ms 196288 KB Output is correct
6 Correct 85 ms 196436 KB Output is correct
7 Correct 83 ms 196436 KB Output is correct
8 Correct 80 ms 196436 KB Output is correct
9 Correct 85 ms 196432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 196432 KB Output is correct
2 Correct 81 ms 196480 KB Output is correct
3 Correct 99 ms 196284 KB Output is correct
4 Correct 81 ms 196432 KB Output is correct
5 Correct 80 ms 196288 KB Output is correct
6 Correct 85 ms 196436 KB Output is correct
7 Correct 83 ms 196436 KB Output is correct
8 Correct 80 ms 196436 KB Output is correct
9 Correct 85 ms 196432 KB Output is correct
10 Execution timed out 1072 ms 196664 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 196432 KB Output is correct
2 Correct 81 ms 196480 KB Output is correct
3 Correct 99 ms 196284 KB Output is correct
4 Correct 81 ms 196432 KB Output is correct
5 Correct 80 ms 196288 KB Output is correct
6 Correct 85 ms 196436 KB Output is correct
7 Correct 83 ms 196436 KB Output is correct
8 Correct 80 ms 196436 KB Output is correct
9 Correct 85 ms 196432 KB Output is correct
10 Execution timed out 1072 ms 196664 KB Time limit exceeded
11 Halted 0 ms 0 KB -