QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#664995 | #5599. Repetitive Song | enze114514 | WA | 0ms | 3812kb | C++20 | 1.3kb | 2024-10-22 00:09:50 | 2024-10-22 00:09:50 |
Judging History
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'