PROBLEM LINK:Author: Pawel Kacprzak DIFFICULTY:CAKEWALK PREREQUISITES:Basic programming PROBLEM:For a given list $N$ people, where each is either a superhero or a villain, joining the fight between superheroes and villains in the given order, decide which side wins or if the fight ends up with a draw. Superheroes win immediately at the earliest time when there are $2$ more superheroes fighting than villains. Villains win immediately at the earliest time when there are $3$ more villains fighting than superheroes. If none of these cases happens, then the fight results in a draw. QUICK EXPLANATION:Whenever a person joins the fight check if one of the sides wins. If yes, print the name of winning group, otherwise continue. If no side wins after all people joined, print draw. EXPLANATION:Solutions to both subtasks are based on the approach described in quick explanation, but they differ complexity of checking if one side wins. Subtask 1In the first subtask $N$ is at most $500$, so after every person joining the fight, one can count the number of superheroes already fighting and villains already fighting, and then decide if either of the sides wins. This results in $O(N^2)$ solution, because for each of $N$ people joining the fight, in $O(N)$ time we are counting the number of superheroes and villains already fighting. Subtask 2In the second subtask $N$ is at most $10^5$, so counting people from the scratch after every joining person will take too much time. However this can be easily avoided by keeping track of counters of superheroes and villains already fighting. After each person joining the fight, we increment exactly one of these counters depending on the type of the joining person and check if either group wins using these counters. This approach works in $O(N)$ time. AUTHOR'S AND TESTER'S SOLUTIONS:
This question is marked "community wiki".
asked 31 Dec '16, 17:39 ![]()
|
Please move the problem to practice section answered 31 Dec '16, 22:41 ![]()
|
Yeah please move the problem to practice section. answered 01 Jan '17, 08:29 ![]()
|
The question cannot be opened since last night. I've been waiting for the question to accept submissions but it shows "Problem is not visible now. Please try again later." answered 01 Jan '17, 09:42 ![]()
|
/dont use break; beacause user may enter more names; instead do this/ include<stdio.h>include<string.h>int main(){ int n,i,j,t,k; char a[15]; scanf("%d",&t); for(i=0;i<t;i++){ int="" s="0,v=0,flag=0;" scanf("%d",&n);="" for(j="0;j<n;j++){" scanf("%s",a);="" k="strlen(a);" if(k="">=3&&a[k-3]=='m'&&a[k-2]=='a'&&a[k-1]=='n') s++; else v++;
} return 0; } answered 01 Jan '17, 12:48 ![]()
|
Can anyone find what's wrong with my code :
answered 01 Jan '17, 16:01 ![]()
|
Where is the bug in my code? include<iostream>include<string>using namespace std; int main() { int n, k, i, o, p, count, flag, counth, countv, w, countvv, counthh; string person, key; cin >> n; key = "woman"; while (n--) { cin >> k; counth = 0; countv = 0; countvv = 0; counthh = 0; for (i = 0; i < k; i++) { flag = 0;
} answered 01 Jan '17, 19:28 ![]()
|
I'm getting a runtime error (NZEC), can't figure out why. Please point out what's wrong with my code.
Here's the link to my submission: https://www.codechef.com/viewsolution/12387811 answered 02 Jan '17, 10:27 ![]()
|
Pleaese tell me where is the bug in my solution. I have tried a lot but I am getting wrong answer. Please help me.
answered 02 Jan '17, 11:58 ![]()
|