Skip to content

Commit 4c129ab

Browse files
authored
Merge pull request ashutosh97#70 from amcs1729/master
Added new question WATCHFB
2 parents 24b537d + b89ea97 commit 4c129ab

File tree

4 files changed

+272
-0
lines changed

4 files changed

+272
-0
lines changed

WATCHFB/Main.class

1.69 KB
Binary file not shown.

WATCHFB/Main.ctxt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#BlueJ class context
2+
comment0.target=Main
3+
comment1.params=stream
4+
comment1.target=LCSin(java.io.InputStream)
5+
comment2.params=
6+
comment2.target=int\ read()
7+
comment3.params=
8+
comment3.target=int\ readInt()
9+
comment4.params=c
10+
comment4.target=boolean\ isSpaceChar(int)
11+
comment5.params=
12+
comment5.target=java.lang.String\ readString()
13+
comment6.params=
14+
comment6.target=byte\ readByte()
15+
comment7.params=
16+
comment7.target=long\ readLong()
17+
comment8.params=args
18+
comment8.target=void\ main(java.lang.String[])
19+
numComments=9

WATCHFB/Main.java

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
import java.io.IOException;
2+
import java.io.InputStream;
3+
import java.util.InputMismatchException;
4+
import java.util.Arrays;
5+
class LCSin
6+
{
7+
private InputStream stream;
8+
private byte[] buf = new byte[1024];
9+
private int curChar;
10+
private int numChars;
11+
private SpaceCharFilter filter;
12+
public LCSin(InputStream stream) {
13+
this.stream = stream;
14+
}
15+
public interface SpaceCharFilter {
16+
public boolean isSpaceChar(int ch);
17+
}
18+
public int read() {
19+
if (numChars == -1)
20+
throw new InputMismatchException();
21+
if (curChar >= numChars) {
22+
curChar = 0;
23+
try {
24+
numChars = stream.read(buf);
25+
} catch (IOException e) {
26+
throw new InputMismatchException();
27+
}
28+
if (numChars <= 0)
29+
return -1;
30+
}
31+
return buf[curChar++];
32+
}
33+
public int readInt() {
34+
int c = read();
35+
while (isSpaceChar(c))
36+
c = read();
37+
int sgn = 1;
38+
if (c == '-') {
39+
sgn = -1;
40+
c = read();
41+
}
42+
int res = 0;
43+
do {
44+
if (c < '0' || c > '9')
45+
throw new InputMismatchException();
46+
res *= 10;
47+
res += c - '0';
48+
c = read();
49+
} while (!isSpaceChar(c));
50+
return res * sgn;
51+
}
52+
public boolean isSpaceChar(int c) {
53+
if (filter != null)
54+
return filter.isSpaceChar(c);
55+
return c==' '||c=='\n'|| c == '\r' || c == '\t' || c == -1;
56+
}
57+
public String readString() {
58+
int c = read();
59+
while (isSpaceChar(c))
60+
c = read();
61+
StringBuilder res = new StringBuilder();
62+
do {
63+
res.appendCodePoint(c);
64+
c = read();
65+
}
66+
while (!isSpaceChar(c));
67+
return res.toString();
68+
}
69+
public byte readByte() {
70+
int c = read();
71+
while (isSpaceChar(c))
72+
c = read();
73+
byte res = 0;
74+
do {
75+
if (c < '0' || c > '9')
76+
throw new InputMismatchException();
77+
res *= 10;
78+
res += c - '0';
79+
c = read();
80+
} while (!isSpaceChar(c));
81+
return res;
82+
}
83+
public long readLong() {
84+
int c = read();
85+
while (isSpaceChar(c))
86+
c = read();
87+
int sgn = 1;
88+
if (c == '-')
89+
{
90+
sgn = -1;
91+
c = read();
92+
}
93+
long res = 0;
94+
do
95+
{
96+
if (c < '0' || c > '9')
97+
throw new InputMismatchException();
98+
res *= 10;
99+
res += c - '0';
100+
c = read();
101+
}
102+
while (!isSpaceChar(c));
103+
return res * sgn;
104+
}
105+
}
106+
107+
public class Main
108+
{
109+
public static void main(String args[])
110+
{
111+
LCSin br= new LCSin(System.in);
112+
int test= br.readInt();
113+
StringBuilder sb=new StringBuilder();
114+
for(int testcase= 0; testcase<test;testcase++)
115+
{
116+
long x=0;
117+
long y=0;
118+
long prevmax=0;
119+
long prevmin=0;
120+
boolean res= false;
121+
122+
int n= br.readInt();
123+
for(int i=0;i<n;i++)
124+
{
125+
int alpha= br.readInt();
126+
long a= br.readInt();
127+
long b= br.readInt();
128+
long max= (long)Math.max(a,b);
129+
long min= (long)Math.min(a,b);
130+
131+
if(a==b)
132+
{
133+
System.out.println("YES");
134+
res= true;
135+
prevmax= a;
136+
prevmin= a;
137+
continue;
138+
}
139+
140+
if(alpha==1)
141+
{
142+
System.out.println("YES");
143+
prevmax= max;
144+
prevmin= min;
145+
res= true;
146+
continue;
147+
}
148+
149+
if(min>prevmax)
150+
{
151+
System.out.println("NO");
152+
prevmax= max;
153+
prevmin= min;
154+
res= false;
155+
continue;
156+
}
157+
158+
if((max>prevmax)&&(min<prevmax))
159+
{
160+
if(res==false)
161+
{System.out.println("NO");}
162+
else
163+
{System.out.println("YES");}
164+
prevmax= max;
165+
prevmin= min;
166+
continue;
167+
168+
}
169+
170+
if((max==prevmax)&&(min<prevmax))
171+
{
172+
if(res==false)
173+
{System.out.println("NO");}
174+
else
175+
{System.out.println("YES");}
176+
prevmax= max;
177+
prevmin= min;
178+
continue;
179+
180+
}
181+
182+
if((max>prevmax)&&(min==prevmax))
183+
{
184+
185+
System.out.println("NO");
186+
res= false;
187+
prevmax= max;
188+
prevmin= min;
189+
continue;
190+
191+
}
192+
}
193+
}
194+
}
195+
}

WATCHFB/WATCHFB.txt

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
The solution given is created by the author and using it without prior written permission from the author can lead to legal actions.
2+
Please contact [email protected] for any queries
3+
4+
5+
6+
https://www.codechef.com/problems/WATCHFB
7+
8+
Chef and his son Chefu want to watch a match of their favourite football team playing against another team, which will take place today.
9+
10+
Unfortunately, Chef is busy in the kitchen preparing lunch, so he cannot watch the match. Therefore, every now and then, Chef asks Chefu about the current scores of the teams and Chefu tells him the score. However, Chefu sometimes does not specify the teams along with the score — for example, he could say "the score is 3 to 6", and there is no way to know just from this statement if it was their favourite team or the other team that scored 6 goals; in different statements, the order of teams may also be different. Other times, Chefu specifies which team scored how many goals.
11+
12+
Chef asks for the score and receives a reply N times. There are two types of replies:
13+
14+
1 A B: their favourite team scored A goals and the other team scored B goals
15+
2 A B: one team scored A goals and the other scored B goals
16+
Chef is asking you to help him determine the score of his favourite team after each of Chefu's replies. After each reply, based on the current reply and all previous information (but without any following replies), tell him whether it is possible to certainly determine the number of goals scored by his favourite team.
17+
18+
Input
19+
The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
20+
The first line of each test case contains a single integer N.
21+
The following N lines describe Chefu's replies in the format described above.
22+
Output
23+
For each of Chefu's replies, print a single line containing the string "YES" if it is possible to determine the score of Chef's favourite team after this reply or "NO" if it is impossible.
24+
25+
Constraints
26+
1=T=100
27+
1=N=104
28+
0=A,B=109
29+
the sum of N over all test cases does not exceed 105
30+
there is at least one valid sequence of scored goals consistent with all replies
31+
Subtasks
32+
Subtask #1 (100 points): original constraints
33+
34+
Example Input
35+
1
36+
6
37+
2 0 1
38+
1 3 1
39+
2 2 4
40+
2 5 6
41+
2 8 8
42+
2 9 10
43+
Example Output
44+
NO
45+
YES
46+
YES
47+
NO
48+
YES
49+
NO
50+
Explanation
51+
Example case 1:
52+
53+
Reply 1: Chef cannot know who scored the first goal.
54+
Reply 2: Chefu told Chef that their favourite team has scored 3 goals so far.
55+
Reply 3: Chef can conclude that his favourite team has scored 4 goals, since it already scored 3 goals earlier.
56+
Reply 4: the favourite team could have scored 5 or 6 goals, but there is no way to know which option is correct.
57+
Reply 5: since there is a tie, Chef knows that his favourite team has scored 8 goals.
58+
Reply 6: again, Chef cannot know if his favourite team has scored 9 or 10 goals.

0 commit comments

Comments
 (0)