QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#662901#5137. TowermoosyWA 3ms3608kbC++201.7kb2024-10-21 11:53:502024-10-21 11:53:52

Judging History

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

  • [2024-10-21 11:53:52]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3608kb
  • [2024-10-21 11:53:50]
  • 提交

answer

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;

    ll tmp[505];

    void Solve() {
        ll n, m; cin >> n >> m;
        vector<ll> a(n + 1);
        set<ll> ans;
        for(ll i = 1; i <= n; i ++ ) {
            cin >> a[i];
            ll x = a[i];
            while(x) {
                ans.insert(x);
                x /= 2;
            }
        }
        ll res = 1e18;
        for(auto x : ans) {
            // vector<ll> tmp;
            for(ll i = 1; i <= n; i ++ ) {
                if(a[i] <= x) {
                    // tmp.push_back(x - a[i]); continue;
                    tmp[i] = x - a[i]; continue;
                }
                ll y = a[i], sum = 0;
                while(1) {
                    if(y / 2 <= x) {
                        sum += min(x - y / 2 + 1, y - x);
                        // tmp.push_back(sum);
                        tmp[i] = sum;
                        break;
                    }   
                    sum ++ ;
                    y /= 2;
                }
            }
            // sort(tmp.begin(), tmp.end());
            nth_element(tmp + 1, tmp + m + 1, tmp + n + 1);
            // for(ll i = 0; i < tmp.size(); i ++ ) {
            //     cout << tmp[i] << " \n"[i == tmp.size() - 1];
            // }    
            ll sum = 0;
            for(ll i = 1; i <= n - m; i ++ ) {
                sum += tmp[i];
            }
            res = min(sum, res);
        }
        cout << res << "\n";
    }

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

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
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: 3ms
memory: 3544kb

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
5
440
110
570
636
994
233
670
55

result:

wrong answer 2nd numbers differ - expected: '3', found: '5'