用map会导致最后一个样例超时,改为unordered_map通过,详细建议参考https://blog.csdn.net/weixin_41256413/article/details/83720314
#include<algorithm>
#include<string>
#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;
int main() {
int N, K;
scanf("%d %d", &N, &K);
int c, s;
string studentName;
unordered_map<string, vector<int> > stu;
for (int i = 0; i < K; i++) {
scanf("%d %d", &c, &s);
for (int j = 0; j < s; j++) {
cin >> studentName;
stu[studentName].push_back(c);
}
}
for (int i = 0; i < N; i++) {
cin >> studentName;
cout << studentName << " " << stu[studentName].size();
sort(stu[studentName].begin(), stu[studentName].end());
for (int k = 0; k < stu[studentName].size(); k++) {
printf(" %d", stu[studentName][k]);
}
printf("\n");
}
return 0;
}