QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#277606#5139. DFS Order 2zzuqy#WA 0ms3820kbC++201.4kb2023-12-06 20:43:362023-12-06 20:43:37

Judging History

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

  • [2023-12-06 20:43:37]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3820kb
  • [2023-12-06 20:43:36]
  • 提交

answer

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
#include <queue>
#include <bitset>
using namespace std;
const int N = 1e5 + 9;
typedef long long ll;
int read() {
  int x = 0, s = 1; char ch = getchar();
  for (; !isdigit(ch); ch = getchar()) if (ch == '-') s = -1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
  return x * s; 
}

int n, m, a[N];

void solve() {
  cin >> n >> m;
  vector<int> cho;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    for (int j = -60; j <= 60; ++j) {
      if (a[i] + j >= 1)
        cho.push_back(a[i] + j);
    }
  }
  sort(cho.begin(), cho.end());
  cho.erase(unique(cho.begin(), cho.end()), cho.end());
  double t2 = log(2);
  int Ans = 1e9 + 9;
  for (int x : cho) {
    vector<int> res;
    for (int i = 1; i <= n; ++i) {
      if (a[i] <= x) {
        res.push_back(x - a[i]); 
      } else {
        int t = log(1.0 *  a[i] / x) / t2;
        t = min(abs((a[i] >> t) - x) + t, abs((a[i] >> t + 1) - x) + t + 1);
        res.push_back(t);
      }
    }
    nth_element(res.begin(), res.begin() + n - m, res.end());
    int ans = 0;
    for (int i = 0; i < n - m; ++i)
      ans += res[i];
    Ans = min(Ans, ans);
  }
  
  cout << Ans << '\n';
}

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

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3820kb

input:

5
1 2
1 3
3 4
3 5

output:

0
0
0
0
0

result:

wrong answer 1st numbers differ - expected: '4', found: '0'