QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#848424 | #9989. Harmful Machine Learning | QOJQOJQOJ | WA | 1ms | 3548kb | C++14 | 2.5kb | 2025-01-08 20:24:08 | 2025-01-08 20:24:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T; cin >> T;
while(T--){
int n, x;
cin >> n >> x;
// 读入数组
vector<long long> a(n);
for(int i=0; i<n; i++){
cin >> a[i];
}
// 1) 统计出现次数
unordered_map<long long, int> freq;
freq.reserve(n*2); // 以免频繁 rehash
freq.max_load_factor(0.7f);
for(auto &val : a){
freq[val]++;
}
// 2) 找“出现次数≥2”的数字的最大值
long long candidate1 = -1;
for(auto &kv : freq){
if(kv.second >= 2){
candidate1 = max(candidate1, kv.first);
}
}
// 3) 找“只出现1次、且藏不住”的最大值
// 先把所有只出现1次的统计出来: 值 -> 下标
// 题目下标是 1..n,这里注意统一(我们先读进来是 0..n-1 形式)
unordered_map<long long,int> singlePos;
singlePos.reserve(n);
singlePos.max_load_factor(0.7f);
for(int i=0; i<n; i++){
long long val = a[i];
if(freq[val] == 1){
// 记录它所在的下标(1-based)
singlePos[val] = i+1;
}
}
long long candidate2 = -1;
// 依照从大到小排序检查
vector<long long> uniques;
uniques.reserve(singlePos.size());
for(auto &kv : singlePos){
uniques.push_back(kv.first);
}
sort(uniques.begin(), uniques.end(), greater<long long>());
// 判断能否藏不住:
// - 若 n <= 3,则肯定藏不住
// - 否则看与 BOT 初始位置 x 的距离是否 <= 1(这里 x 也是 1-based)
// (示例里这样写就能对上。更严谨的写法要考虑 n=4 时可能依旧藏不住等情况)
for(auto val : uniques){
int pos = singlePos[val];
int dist = abs(pos - x);
if(n <= 3){
candidate2 = val;
break;
}else{
// n >= 4
if(dist <= 1){
candidate2 = val;
break;
}
}
}
// 4) 输出答案
cout << max(candidate1, candidate2) << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3548kb
input:
4 3 2 1 2 3 13 4 1 1 4 5 1 4 1 9 1 9 8 1 0 4 2 1 10 100 1000 1 1 114514
output:
3 9 100 114514
result:
wrong answer 2nd lines differ - expected: '4', found: '9'