如果你 WA #1 且输出严格第三大值
查看原帖
如果你 WA #1 且输出严格第三大值
937928
Estrella_Explore楼主2024/11/7 13:56

该解法是伪的

Hack: #1

3 
9 5 3 

输出严格第三大值,在这个样例里是 3 mod 9=3 3 \space \text{mod} \space 9 = 3,但是实际上本样例的答案是 9 mod 5=49 \space \text{mod} \space 5 = 4

我的唐诗代码如下,调个这题调 10min,差点给我整怀疑人生了

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

const int MAX = 2e5 + 114;
int n;
vector<int> a;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n;

    a.resize(n);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());

    if (a.size() <= 2) {
        cout << -1 << endl;
    } else {
        cout << a[a.size() - 3] << endl;
    }
}
2024/11/7 13:56
加载中...