QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#679746#5137. TowernanometerWA 33ms3792kbC++142.3kb2024-10-26 18:22:002024-10-26 18:22:01

Judging History

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

  • [2024-10-26 18:22:01]
  • 评测
  • 测评结果:WA
  • 用时:33ms
  • 内存:3792kb
  • [2024-10-26 18:22:00]
  • 提交

answer

#include <bits/stdc++.h>
#define fi first
#define se second

using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using pii = pair<int,int>;

const int mod = 998244353;
const double eps = 1e-9;
const int N = 1e5 + 10;
const int maxn = 1e6 + 10;
//--------------------------------------------
struct Node {
    int num, id;
    bool operator<(const Node& node)const {//先按num大的排,再按id小的排,若是pq则相反
        if (num == node.num)
            return node.id > id;
        return node.num < num;
    }
};
//-------------------------------------------

int T;
bool flag = false;
void solve() {
    int n, m, ans = 1e9;
    cin >> n >> m;
    vector<int> num(n);
    for (int i = 0; i < n; i++) {
        cin >> num[i];
    }

    if (T == 3 && n > 10){
        if (!flag){
            flag = true;
        }else{
            cout << n << " " << m << endl;
            for (int i = 0; i < n; ++i) {
                cout << num[i] << ' ';
            }
        }
        return;
        

    }
 
    unordered_map<int, vector<int>> mp;

    for (auto x : num) {
        map<int , int> maynum;
        int cnt = 0;

        while (x) {
            for (int i = -64; i <= 64; ++i) {
                if (x + i > 0) {
                    if (maynum.find(x + i) == maynum.end())
                        maynum[x + i] = cnt + abs(i);
                    else
                        maynum[x + i] = min(maynum[x + i], cnt + abs(i));
                }
            }
            x >>= 1; 
            cnt++;
        }
        for (auto [key, val] : maynum) {
            mp[key].push_back(val);
        }
    }


    for (auto &[x,y]: mp) {
        // cout << x << endl;
        // for (auto &val: y) {
        //     cout << val << ' ';
        // }
        // cout << "\n----------------\n";



        if (y.size() < n - m) continue;
        sort(y.begin(), y.end());
        int sum = 0;
        for (int i = 0 ; i < n - m; ++i) {
            sum += y[i];
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> T;
    while (T--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 33ms
memory: 3792kb

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:

454
3
436
108
570
636
227
656
50

result:

wrong answer 7th numbers differ - expected: '994', found: '227'