# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
659535 |
2022-11-18T11:52:32 Z |
onebit1024 |
Stove (JOI18_stove) |
C++17 |
|
234 ms |
468 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define all(c) c.begin(), c.end()
#define endl "\n"
const double PI=3.141592653589;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "LINE(" << __LINE__ << ") -> " <<"[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
vector<int>a;
int n,k;
void solve()
{
cin >> n >> k;
a.resize(n);
int ans = 1e10;
for(int &u : a)cin >> u;
for(int i = 0;i<(1ll<<22);++i){
int val = __builtin_popcount(i);
if(val%2)continue;
int op = val/2;
if(op > k)continue;
bool m = 0;
int start = 0, end = 0;
vector<int>taken(22);
int res = 0;
for(int j = 0;j<22;++j){
if(i&(1ll<<j)){
if(!m){
start = j;
}else{
end = j;
for(int k = start;k<end;++k)taken[k] = 1;
res+=(end-start);
}
m = !m;
}
}
bool ok = 1;
for(auto x : a){
if(!taken[x]){
ok = 0;
}
}
if(!ok)continue;
ans = min(ans, res);
}
cout << ans << endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int T=1;
for(int i = 1;i<=T;++i)
{
// cout << "Case #" << i << ": ";
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
212 KB |
Output is correct |
2 |
Correct |
26 ms |
316 KB |
Output is correct |
3 |
Correct |
119 ms |
300 KB |
Output is correct |
4 |
Correct |
234 ms |
304 KB |
Output is correct |
5 |
Correct |
227 ms |
300 KB |
Output is correct |
6 |
Correct |
19 ms |
320 KB |
Output is correct |
7 |
Correct |
226 ms |
300 KB |
Output is correct |
8 |
Correct |
234 ms |
300 KB |
Output is correct |
9 |
Correct |
19 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
212 KB |
Output is correct |
2 |
Correct |
26 ms |
316 KB |
Output is correct |
3 |
Correct |
119 ms |
300 KB |
Output is correct |
4 |
Correct |
234 ms |
304 KB |
Output is correct |
5 |
Correct |
227 ms |
300 KB |
Output is correct |
6 |
Correct |
19 ms |
320 KB |
Output is correct |
7 |
Correct |
226 ms |
300 KB |
Output is correct |
8 |
Correct |
234 ms |
300 KB |
Output is correct |
9 |
Correct |
19 ms |
332 KB |
Output is correct |
10 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
212 KB |
Output is correct |
2 |
Correct |
26 ms |
316 KB |
Output is correct |
3 |
Correct |
119 ms |
300 KB |
Output is correct |
4 |
Correct |
234 ms |
304 KB |
Output is correct |
5 |
Correct |
227 ms |
300 KB |
Output is correct |
6 |
Correct |
19 ms |
320 KB |
Output is correct |
7 |
Correct |
226 ms |
300 KB |
Output is correct |
8 |
Correct |
234 ms |
300 KB |
Output is correct |
9 |
Correct |
19 ms |
332 KB |
Output is correct |
10 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |