最后一个测试点有几率不超时
1 #include <iostream> 2 #include <string> 3 #include <map> 4 #include <vector> 5 #include <algorithm> 6 using namespace std; 7 int main() 8 { 9 map<string,vector<int>>chosen; 10 int N, K; 11 cin >> N >> K; 12 for (int i = 0; i < K; i++) 13 { 14 int a, b; 15 scanf("%d %d",&a,&b); 16 for (int j = 0; j < b; j++) 17 { 18 char s[5]; 19 scanf("%s",s); 20 chosen[s].push_back(a); 21 } 22 } 23 for (int i = 0; i < N; i++) 24 { 25 char s[5]; 26 scanf("%s",s); 27 sort(chosen[s].begin(),chosen[s].end()); 28 printf("%s %d",s,chosen[s].size()); 29 for (int j = 0; j < chosen[s].size(); j++) 30 { 31 printf(" %d",chosen[s][j]); 32 } 33 printf("\n"); 34 } 35 return 0; 36 }