QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#664995#5599. Repetitive Songenze114514WA 0ms3812kbC++201.3kb2024-10-22 00:09:502024-10-22 00:09:50

Judging History

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

  • [2024-10-22 00:09:50]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3812kb
  • [2024-10-22 00:09:50]
  • 提交

answer

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

#define pb push_back

const ld pi = 3.14159265358979323846;
const ll INF = 1e18;
const int mod = (int)1e9 + 7;

template<typename T>
T chmax(T a, T b) {
    return a > b ? a : b;
}

template<typename T>
T chmin(T a, T b) {
    return a > b ? b : a;
}

const int N = 3e3 + 1, M = N * 2;


void solve() {
    int n;
    cin >> n;

    map<string, int> mp;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        mp[s]++;
    }

    vector<int> a;
    for(auto [k, v] : mp){
        a.pb(v);
    }

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

    int qwq = 0;

    for(int i = 0, j = a.size() - 1; i < j; ){
        if(a[j] > a[i]){
            qwq += a[i] * 2;
            a[j] -= a[i];
            i++;
        }
        else if(a[i] > a[j]){
            qwq += a[j] * 2;
            a[i] -= a[j];
            j--;
        }
        else{
            qwq += a[i] * 2;
            i++, j--;
        }
    }
    cout << (qwq == n ? qwq : qwq + 1) << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    // cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3592kb

input:

10
bow
bow
chick
chicka
chicka
bow
bow
chick
chicka
chicka

output:

9

result:

ok single line: '9'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3812kb

input:

31
head
shoulders
knees
and
toes
knees
and
toes
head
shoulders
knees
and
toes
knees
and
toes
eyes
and
ears
and
mouth
and
nose
head
shoulders
knees
and
toes
knees
and
toes

output:

31

result:

wrong answer 1st lines differ - expected: '29', found: '31'