-
数据量很大的时候最好用
char数组
和scanf
,否则很容易超时。
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int N, K;
const int MAX_N = 40000 + 5;
const int MAX_K = 2500 + 5;
char names[MAX_N][5];
vector<int> res[MAX_K];
bool cmp(int a, int b) {
return strcmp(names[a], names[b]) < 0;
}
int main() {
scanf("%d %d", &N, &K);
for (int n = 0; n < N; n++) {
int C;
scanf("%s %d", names[n], &C);
for (int c = 0; c < C; c++) {
int number;
scanf("%d", &number);
res[number].push_back(n);
}
}
for (int k = 1; k <= K; k++) {
printf("%d %d\n", k, res[k].size());
sort(res[k].begin(), res[k].end(), cmp);
for (auto it : res[k]) {
printf("%s\n", names[it]);
}
}
return 0;
}
/*
Sample Input:
10 5
ZOE1 2 4 5
ANN0 3 5 2 1
BOB5 5 3 4 2 1 5
JOE4 1 2
JAY9 4 1 2 5 4
FRA8 3 4 2 5
DON2 2 4 5
AMY7 1 5
KAT3 3 5 4 2
LOR6 4 2 4 1 5
Sample Output:
1 4
ANN0
BOB5
JAY9
LOR6
2 7
ANN0
BOB5
FRA8
JAY9
JOE4
KAT3
LOR6
3 1
BOB5
4 7
BOB5
DON2
FRA8
JAY9
KAT3
LOR6
ZOE1
5 9
AMY7
ANN0
BOB5
DON2
FRA8
JAY9
KAT3
LOR6
ZOE1
*/