알고리즘
백준 3758번 KCPC C++
영춘권의달인
2023. 3. 12. 11:56
https://www.acmicpc.net/problem/3758
3758번: KCPC
입력 데이터는 표준 입력을 사용한다. 입력은 T개의 테스트 데이터로 구성된다. 입력의 첫 번째 줄에는 테스트 데이터의 수를 나타내는 정수 T가 주어진다. 각 테스트 데이터의 첫 번째 줄에는
www.acmicpc.net
각 팀의 id, 최종 점수, 제출 횟수, 마지막 제출 시간의 정보를 구조체로 묶어서 조건에 맞게 정렬되도록 비교 연산자를 재정의하였다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
struct Info {
int id;
int totalScore;
int submitCnt;
int lastSubmitTime;
bool operator<(const Info& other) const {
if (totalScore == other.totalScore) {
if (submitCnt == other.submitCnt) {
return lastSubmitTime < other.lastSubmitTime;
}
else {
return submitCnt < other.submitCnt;
}
}
else {
return totalScore > other.totalScore;
}
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
int n, k, myId, m;
cin >> n >> k >> myId >> m;
map<pair<int, int>, int> score;
vector<Info> v = vector<Info>(n + 1);
for (int i = 1; i <= n; i++) {
v[i] = { i,0,0,0 };
}
for (int i = 0; i < m; i++) {
int id, j, s;
cin >> id >> j >> s;
auto it = score.find({ id,j });
if (it == score.end()) {
score.insert({ {id,j},s });
}
else {
it->second = max(it->second, s);
}
v[id].lastSubmitTime = i;
v[id].submitCnt++;
}
for (auto a : score) {
int id = a.first.first;
v[id].totalScore += a.second;
}
sort(v.begin() + 1, v.end());
int ans = -1;
for (int i = 1; i <= n; i++) {
if (v[i].id == myId) {
ans = i;
break;
}
}
cout << ans << "\n";
}
}