QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#647905 | #5137. Tower | comp_towels_cat | WA | 9ms | 3712kb | C++17 | 3.6kb | 2024-10-17 16:08:32 | 2024-10-17 16:08:32 |
Judging History
answer
//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define FOR(i, j, k) for(int i = (j);i <= (k);i ++)
#define ROF(i, j, k) for(int i = (j);i >= (k);i --)
#define For(i, j, k) for(int i = (j);i < (k);i ++)
#define Rof(i, j, k) for(int i = (j);i > (k);i --)
#define ull unsigned long long
#define int long long
#define PII pair<int,int>
#define ULL unsigned long long
#define db double
#define x first
#define y second
#define sp(x) fixed << setprecision(x)
#define all(x) x.begin(), x.end()
#define unq_all(x) x.erase(unique(all(x)), x.end())
#define M(x) x %= mod, x += mod, x %= mod
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define Yes cout << "Yes\n"
#define No cout << "No\n"
#define ANS cout << ans << '\n'
#define de(p) cout << #p << ' ' << p << '\n'
#define END(i, n) (i == n ? '\n' : ' ')
#define double long double
#define RED cout << "\033[91m"
#define GREEN cout << "\033[92m"
#define YELLOW cout << "\033[93m"
#define BLUE cout << "\033[94m"
#define MAGENTA cout << "\033[95m"
#define CYAN cout << "\033[96m"
#define RESET cout << "\033[0m"
// 红色
#define DEBUG1(x) \
RED; \
cout << #x << " : " << x << endl; \
RESET;
// 绿色
#define DEBUG2(x) \
GREEN; \
cout << #x << " : " << x << endl; \
RESET;
// 蓝色
#define DEBUG3(x) \
BLUE; \
cout << #x << " : " << x << endl; \
RESET;
// 品红
#define DEBUG4(x) \
MAGENTA; \
cout << #x << " : " << x << endl; \
RESET;
// 青色
#define DEBUG5(x) \
CYAN; \
cout << #x << " : " << x << endl; \
RESET;
// 黄色
#define DEBUG6(x) \
YELLOW; \
cout << #x << " : " << x << endl; \
RESET;
using namespace std;
const int N = 5e5 + 10, M = 1e5 + 10, INF = 1e9, mod = 998244353;
int n, m, k;
int a[N];
int cal(int x, int y) //y->x
{
if (x >= y) {
return x - y;
}
if (x == 0) {
int res = 0;
while (y) {
res ++;
y /= 2;
}
return res;
}
// y > x
int res = 1e17;
int step = 0;
int mx = x, my = y;
while (y*2 >= x) {
res = min(res, step + abs(y - x));
x *= 2;
step++;
}
x = mx; y = my;
step = 0;
while (y >= x) {
res = min(res, step + abs(y - x));
step ++;
if (y == 0) break;
y /= 2;
}
return res;
}
int get(int x)
{
priority_queue<int,vector<int>,greater<>> q;
FOR(i,1,n)
{
q.push(cal(x,a[i]));
}
int res = 0;
FOR(i,1,n - m)
{
res += q.top();
q.pop();
}
return res;
}
void solve()
{
cin >> n >> m;
set<int> se;
FOR(i,1,n)
{
cin >> a[i];
int t = a[i];
while (t)
{
se.insert(t);
t >>= 1;
}
}
se.insert(0);
int ans = 1e9;
for(auto i : se)
{
ans = min(ans,get(i));
}
ANS;
}
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
auto t = clock();
int T = 1;
cin >> T;
while (T--)
{
solve();
}
auto tt = clock();
// cout << "Time: " << 1000.0 * (tt - t) / CLOCKS_PER_SEC << "ms" << endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3708kb
input:
3 2 0 2 6 5 0 1 2 3 4 5 5 3 1 2 3 4 5
output:
2 4 1
result:
ok 3 number(s): "2 4 1"
Test #2:
score: -100
Wrong Answer
time: 9ms
memory: 3712kb
input:
10 272 118 11 14 49 94 71 62 46 45 74 22 15 36 7 37 27 35 96 85 75 78 76 64 23 59 17 35 71 28 96 82 5 66 2 48 57 31 88 10 61 73 79 23 19 52 39 76 48 98 5 39 48 51 90 90 60 27 47 24 24 56 48 27 39 21 38 18 20 9 62 83 47 15 51 22 73 74 7 80 64 60 86 74 59 7 84 38 99 31 42 60 52 41 63 88 59 90 77 40 68...
output:
477 3 466 114 589 659 1037 235 674 52
result:
wrong answer 1st numbers differ - expected: '454', found: '477'