QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#647559#5137. TowerbhscerWA 125ms3608kbC++172.2kb2024-10-17 14:43:532024-10-17 14:44:01

Judging History

你现在查看的是最新测评结果

  • [2024-10-17 14:44:01]
  • 评测
  • 测评结果:WA
  • 用时:125ms
  • 内存:3608kb
  • [2024-10-17 14:43:53]
  • 提交

answer

#include <bits/stdc++.h>

#define int long long
#define fadd(a,b,c) for (int a=b;a<=c;a++)
#define fsub(a,b,c) for (int a=b;a>=c;a--)
#define F first
#define S second
#define CYes cout << "Yes\n"
#define CNo cout << "No\n"
#define CYES cout << "YES\n"
#define CNO cout << "NO\n"
#define println(a) cout << (a) << '\n'

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;
void fastIO(){ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
class bhscer {
public:
    template<typename FIRST, typename ...PACK> static void debug(FIRST first, PACK... params) { std::cout<< first <<' '; debug(params...);}
    template<typename T> static void debug(T end) { std::cout << end << std::endl; }
};
const int N = 5e5;
int a[N];

int cal(int x, int y) {
    if (x >= y) {
        return x - y;
    }
    // y > x
    int my = y;
    int res = 1e17;
    int step = 0;
    while (y >= x) {
        int cur = step + (y - x);
        res = min(res, cur);
        step++;
        if (y == 0) break;
        y /= 2;
    }
    res = min(res, (my+1)/2*2 - my + step);
    return res;
}
void solve() {
    int n,m; cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    int ans = 1e17;
    for (int i=1;i<=n;i++) {
        int x = a[i];

        // cout << " > " << x << endl;
        while (true) {
            priority_queue<int, vector<int>, greater<int>> q;
            int curCost = 0;
            for (int j=1;j<=n;j++) {
                if (j == i) {
                    curCost = cal(x, a[j]);
                } else {
                    q.push(cal(x, a[j]));
                }
            }
            int cur = curCost;
            for (int j=1;j<=n-m-1;j++) {
                cur += q.top();
                q.pop();
            }
            ans = min(ans, cur);
            // cout << x << endl;
            if (x == 0) break;
            x /= 2;
            // cout << " -> " << x << endl;
        }
    }
    println(ans);
}
signed main() {
    fastIO();
    int _ = 1;
    cin >> _;
    while (_--) {
        solve();
//        int x,y; cin >> x >> y;
//        println(cal(x,y));
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3608kb

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: 125ms
memory: 3600kb

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:

230
3
246
59
267
485
645
130
413
25

result:

wrong answer 1st numbers differ - expected: '454', found: '230'