Q1: Research Groups In response to popular demand, Dan’s established two research groups A and B composed of his n graduate students. Each of these students is a member of exactly one of the two groups at any given time. The students are numbered from 1 to n in some arbitrary order. To measure the success of his research groups, Dan assigns a citation score to each of them. Initially, both groups have citation score 0. Throughout the semester, events of the following two types happen: Student x publishes a paper in which they cite student y’s work (youcan assume all of the students have been around long enough to have prior research that can be cited). As a result, If x and y are in the same group, their group’s citation score increases by 1. If x and y are in different groups, y’s group’s citation score increases by 5. Dan changes student x’s group (from A to B or from B to A) to have them work on different projects. To assess the overall success of the research groups, Dan needs to calculate their final citation scores at the end of the semester. Help him do so by writing a program that reports the final scores given a description of the events occurring throughout the semester. Input The first line of the input contains two integers n and m separated by a single space. n denotes the number of Dan’s students and m denotes the number of events. The second line contains n letters separated by single spaces. The i-th letter is either “A” or “B”. If it’s “A”, the i-th student is initially in group A; Otherwise, the i-th student is initially in group B. The next m lines describe the events in chronological order. Each line describes a single event. If a line starts with the string cite, two integers x and y follow, indicating that student x has published a paper in which they cite student y’s work. Otherwise, the line starts with the string change, which is followed by a single integer x. This indicates that Dan has changed student x’s group. Output Print two integers separated by a single space. These should indicate the final citation scores of groups A and B, respectively. Sample Input 1 6 5 A A B B B B cite 1 3 cite 1 2 change 1 cite 2 1 cite 4 2 Sample Output 1 6 10 Sample 1 Explanation The first line indicates that there are 6 students and 5 events. The second line indicates that the first two students are in group A while the remaining four are in group B. In the first event, student 1 cites student 3’s work. Since they are in different groups, group B (student 3’s group) scores 5 points. Student 1 cites student 2’s work. Since they are both in group A, group A scores 1 point. Dan changes student 1’s group (from group A to group B). Student 2 then cites student 1’s work. Group B scores 5 points. Finally, student 4 cites student 2’s work. Group A scores 5 points. In total, group A scores 6 points and group B scores 10 points, which is reflected in the output. Sample Input 2 3 6 A A A cite 3 1 change 1 cite 1 2 change 1 change 2 cite 2 1 Sample Output 2 11 0 I submitted this question before but I don't think it was the right solution. Because when you go to type the input it fives an error I came up to conclusion that we should start the code like this: n = input() lst = n.split() m = int(lst[1]) group_type = [] for i in range(0, m): events = input() group_type.append(events) a = 0 b = 0 But the rest of the code I was unable to complete could you please help me figure out this code.
Q1: Research Groups
In response to popular demand, Dan’s established two research groups A and B composed of his n graduate students. Each of these students is a member of exactly one of the two groups at any given time. The students are numbered from 1 to n in some arbitrary order.
To measure the success of his research groups, Dan assigns a citation score to each of them. Initially, both groups have citation score 0. Throughout the semester, events of the following two types happen:
-
Student x publishes a paper in which they cite student y’s work (youcan assume all of the students have been around long enough to have prior research that can be cited). As a result,
If x and y are in the same group, their group’s citation score increases by 1.
If x and y are in different groups, y’s group’s citation score increases by 5.
-
Dan changes student x’s group (from A to B or from B to A) to have them
work on different projects.
To assess the overall success of the research groups, Dan needs to calculate their final citation scores at the end of the semester. Help him do so by writing a
Input
The first line of the input contains two integers n and m separated by a single space. n denotes the number of Dan’s students and m denotes the number of events.
The second line contains n letters separated by single spaces. The i-th letter is either “A” or “B”. If it’s “A”, the i-th student is initially in group A; Otherwise, the i-th student is initially in group B.
The next m lines describe the events in chronological order. Each line describes a single event. If a line starts with the string cite, two integers x and y follow, indicating that student x has published a paper in which they cite student y’s work.
Otherwise, the line starts with the string change, which is followed by a single integer x. This indicates that Dan has changed student x’s group.
Output
Print two integers separated by a single space. These should indicate the final citation scores of groups A and B, respectively.
Sample Input 1
6 5
A A B B B B
cite 1 3
cite
1 2
change 1
cite 2 1
cite 4 2
Sample Output 1
6 10
Sample 1 Explanation
The first line indicates that there are 6 students and 5 events.
The second line indicates that the first two students are in group A while the remaining four are in group B.
In the first event, student 1 cites student 3’s work. Since they are in different groups, group B (student 3’s group) scores 5 points.
Student 1 cites student 2’s work. Since they are both in group A, group A scores 1 point.
Dan changes student 1’s group (from group A to group B).
Student 2 then cites student 1’s work. Group B scores 5 points. Finally, student 4 cites student 2’s work. Group A scores 5 points.
In total, group A scores 6 points and group B scores 10 points, which is reflected in the output.
Sample Input 2
3 6
A A A
cite 3 1
change 1
cite 1 2
change 1
change 2
cite 2 1
Sample Output 2
11 0
I submitted this question before but I don't think it was the right solution. Because when you go to type the input it fives an error I came up to conclusion that we should start the code like this:
n = input()
lst = n.split()
m = int(lst[1])
group_type = []
for i in range(0, m):
events = input()
group_type.append(events)
a = 0
b = 0
But the rest of the code I was unable to complete could you please help me figure out this code.
Step by step
Solved in 3 steps with 3 images