QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#842358 | #9370. Gambling on Choosing Regionals | pipizhu | TL | 0ms | 3628kb | C++20 | 3.2kb | 2025-01-04 11:59:18 | 2025-01-04 11:59:18 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
//vector<int> maxP(m, 0);
int bestContest = INT_MAX;
for (int i = 0; i < m; ++i) {
int temp;
cin >> temp;
bestContest = min(bestContest, temp);
}
unordered_map<string, vector<int>> teamMap; //(uniName, allTeam)
vector<pair<string, int>> teamInfo;
for (int i = 0; i < n; ++i) {
int curStrength;
string curUni;
cin >> curStrength >> curUni;
if (teamMap.contains(curUni)) {
teamMap[curUni].push_back(curStrength);
}else {
vector<int> strengthList;
strengthList.push_back(curStrength);
teamMap.emplace(curUni, strengthList);
}
teamInfo.emplace_back(curUni, curStrength);
}
//int bestContest = ranges::min(maxP);
for (auto& pair : teamMap) {
ranges::sort(pair.second, greater<>{});
}
for (int i = 0; i < n; ++i) {
int rank = 1;
string curUni = teamInfo[i].first;
int curStrength = teamInfo[i].second;
for (auto pair : teamMap) {
if (curUni == pair.first) { //when uni same
for (int j = 0; j < bestContest - 1; ++j) {
if (j >= pair.second.size()) break;
if (pair.second[j] == curStrength) {
continue;
}
if (pair.second[j] > curStrength) {
rank ++;
}
}
}else {
int ans = 0;;
int l = 0;
int r = bestContest - 1;
bool flag = true;
if (l == r) {
if (curStrength < pair.second[0]) {
ans = 1;
}
flag = false;
}
if (curStrength > pair.second[l]) {ans = 0; flag = false;}
if (curStrength < pair.second[r]) {ans = r + 1; flag = false;}
if (flag) {
while (true) {
if (l + 1 == r) {
if (pair.second[r] > curStrength) {
ans = l + 1;
}else {
ans = r + 1;
}
break;
}
int mid = (l + r) / 2;
if (pair.second[mid] < curStrength) {
r = mid;
}else {
l = mid;
}
}
}
rank += ans;
// for (int j = 0; j < bestContest; ++j) {
//
// if (j >= pair.second.size()) break;
//
// if (pair.second[j] > curStrength) {
// rank ++;
// }
// }
}
}
cout << rank << endl;
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3560kb
input:
5 3 1 2 3 100 THU 110 PKU 95 PKU 105 THU 115 PKU
output:
2 1 2 2 1
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
5 2 2 3 100 THU 110 PKU 95 PKU 105 THU 115 PKU
output:
4 2 4 3 1
result:
ok 5 lines
Test #3:
score: -100
Time Limit Exceeded
input:
100000 100000 57148 51001 13357 71125 98369 67226 49388 90852 66291 39573 38165 97007 15545 51437 89611 41523 27799 15529 16434 44291 47134 90227 26873 52252 41605 21269 9135 55784 70744 17563 79061 73981 70529 35681 91073 52031 23811 79501 1607 46365 76868 72137 71041 29217 96749 46417 40199 55907 ...
output:
1000 999 1000 1000 1000 1000 1000 1000 1000 869 1000 958 1000 1000 1000 1000 999 1000 1000 1000 1000 1000 1000 990 1000 1000 1000 631 1000 1000 1000 956 1000 1000 1000 1000 1000 1000 575 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 993 1000 1000 999 1000 995 1000 1...