제출 #1119546

#제출 시각아이디문제언어결과실행 시간메모리
1119546luvnaK개의 묶음 (IZhO14_blocks)C++14
0 / 100
1 ms596 KiB
#include<bits/stdc++.h> #define MASK(i) (1 << (i)) #define pub push_back #define all(v) v.begin(), v.end() #define compact(v) v.erase(unique(all(v)), end(v)) #define pii pair<int,int> #define fi first #define se second #define endl "\n" #define sz(v) (int)(v).size() #define dbg(x) "[" #x " = " << (x) << "]" using namespace std; template<class T> bool minimize(T& a, T b){if(a > b) return a = b, true;return false;} template<class T> bool maximize(T& a, T b){if(a < b) return a = b, true;return false;} typedef long long ll; typedef long double ld; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); ll rand(ll l, ll r){return uniform_int_distribution<ll>(l, r)(rng);} const int N = 1e5 + 15; const int MOD = 1e9 + 7; int n, k; int a[N]; int dp[2][N]; bool past = 0, succ = 1; void dnc(int l, int r, int bestL, int bestR){ if(l > r) return; int mid = (l+r) >> 1; int pos = -1; dp[succ][mid] = MOD; int mx = 0; for(int i = min(mid,bestR); i >= bestL; i--){ maximize(mx, a[i]); if(minimize(dp[succ][mid], dp[past][i-1] + mx)) pos = i; } dnc(l,mid-1,bestL,pos); dnc(mid+1,r,pos,bestR); } void solve(){ cin >> n >> k; for(int i = 1; i <= n; i++) cin >> a[i]; dp[past][0] = 0; for(int i = 1; i <= n; i++) dp[past][i] = MOD; for(int i = 1; i <= k; i++){ dnc(1,n,1,n); swap(past, succ); dp[past][0] = MOD; } cout << dp[past][n]; } signed main(){ ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); #define task "task" if(fopen(task".INP", "r")){ freopen(task".INP", "r", stdin); freopen(task".OUT", "w", stdout); } int t; t = 1; //cin >> t; while(t--) solve(); }

컴파일 시 표준 에러 (stderr) 메시지

blocks.cpp: In function 'int main()':
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(task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen(task".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...