emm,cin输入对效率的影响可真是太大了,这个题只能读取string用cin其他数据只能用scanf,不然最后测试点超时!
附本人AC代码:
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
map<int, vector<string>>Ma;
int main() {
string name;
int N, K, num, course;
scanf("%d%d", &N, &K);
for (int i = 0; i < N; i++) {
char A[5];
cin >> name;
scanf("%d",&num);
for (int j = 0; j < num; j++) {
scanf("%d", &course);
Ma[course].push_back(name);
}
}
for (int i = 1; i <= K;i++) {
cout << i << " " << Ma[i].size() << endl;
sort(Ma[i].begin(), Ma[i].end());
for (auto ii = Ma[i].begin(); ii != Ma[i].end(); ii++) {
printf("%s\n", (*ii).c_str());
}
}
return 0;
}