Submission #1287636

#TimeUsernameProblemLanguageResultExecution timeMemory
1287636maxphastStove (JOI18_stove)C++20
50 / 100
1096 ms2780 KiB
/* * @Author: MaxPhast * @File: test.cpp * @Date: 2025-11-05 03:09:44 */ #include <bits/stdc++.h> using namespace std; #define int long long #define ii pair <int , int> #define iii pair <int , ii> #define iiii pair <ii , ii> #define FOR(i , l , r) for(int i = (l) , _r = (r) ; i <= _r ; ++ i) #define FORD(i , r , l) for(int i = (r) , _l = (l) ; i >= _l ; -- i) #define ALL(vec) vec.begin() , vec.end() #define UNI(vec) sort(ALL(vec)) , vec.erase(unique(ALL(vec)) , vec.end()) #define pb push_back #define MASK(i) (1ll << i) #define BIT(mask , i) ((mask >> i) & 1ll) #define ON(mask , i) (mask | MASK(i)) #define OFF(mask , i) (mask & (~MASK(i))) #define TURN(mask , i) (mask ^ MASK(i)) #define BP(mask) __builtin_popcountll(mask) #define sqr(x) (1ll * (x) * (x)) #define fi first #define se second #define oo 1e18 #define time() cerr << " \n " << "Time : " << 1000.0 * clock() / CLOCKS_PER_SEC << "ms." #define IO(TASK) if(fopen(#TASK".INP" , "r")){freopen(#TASK".INP" , "r" , stdin); freopen(#TASK".OUT" , "w" , stdout);} template <class X , class Y> bool maxz(X &a , const Y b) { if(a < b) { a = b; return true; } return false; } template <class X , class Y> bool minz(X &a , const Y b) { if(a > b) { a = b; return true; } return false; } namespace MaxPhast { const int N = 1e5 + 5; int n , k; int a[N] , dp[2][N]; void solve() { cin >> n >> k; FOR(i , 1 , n) cin >> a[i]; sort(a + 1 , a + 1 + n); FOR(j , 0 , n) dp[0][j] = oo; dp[0][0] = 0; FOR(i , 1 , k) { FOR(j , 0 , n) dp[i & 1][j] = oo; FOR(j , i , n) { minz(dp[i & 1][j] , min(dp[i & 1][j - 1] + a[j] - a[j - 1] , dp[i & 1 ^ 1][j - 1] + 1)); } } cout << dp[k & 1][n]; } } signed main() { ios_base :: sync_with_stdio(false) ; cin.tie(nullptr) ; cout.tie(nullptr); IO(test); MaxPhast :: solve(); time(); } /* */

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:29:54: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 | #define IO(TASK) if(fopen(#TASK".INP" , "r")){freopen(#TASK".INP" , "r" , stdin); freopen(#TASK".OUT" , "w" , stdout);}
      |                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:93:5: note: in expansion of macro 'IO'
   93 |     IO(test);
      |     ^~
stove.cpp:29:90: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 | #define IO(TASK) if(fopen(#TASK".INP" , "r")){freopen(#TASK".INP" , "r" , stdin); freopen(#TASK".OUT" , "w" , stdout);}
      |                                                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:93:5: note: in expansion of macro 'IO'
   93 |     IO(test);
      |     ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...