Skip to content

Commit 24b537d

Browse files
authored
Merge pull request ashutosh97#71 from amcs1729/master
ZOMCAV
2 parents 051f069 + 369409c commit 24b537d

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed

ZOMCAV/ZOMCAV.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
The solution given along is written solely by the author and using it anywhere else without prior written permission might result in legal actions taken against the guilty person
2+
3+
4+
5+
6+
7+
There are N caves in a row, numbered 1 through N. For each valid i, the radiation power in the i-th cave is Ci. Originally, the radiation level in each cave was 0. Then, for each valid i, the radiation power in cave i increased the radiation levels in the caves i-Ci,�,i+Ci inclusive (if they exist) by 1, so all the caves are radioactive now.
8+
9+
Radiation is not the only problem, though. There are also N zombies with health levels H1,H2,�,HN. You want to kill all of them by getting them to the caves in such a way that there is exactly one zombie in each cave. A zombie dies in a cave if and only if the radiation level in that cave is equal to the health level of the zombie. Is it possible to kill all the zombies?
10+
11+
Input
12+
The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
13+
The first line of each test case contains a single integer N.
14+
The second line contains N space-separated integers C1,C2,�,CN.
15+
The third line contains N space-separated integers H1,H2,�,HN.
16+
Output
17+
For each test case, print a single line containing the string "YES" if it is possible to kill all the zombies or "NO" if it is impossible (without quotes).
18+
19+
Constraints
20+
1=T=100
21+
1=N=105
22+
1=Ci,Hi=109 for each valid i
23+
Subtasks
24+
Subtask #1 (30 points): 1=N=1,000
25+
Subtask #2 (70 points): original constraints
26+
27+
Example Input
28+
2
29+
5
30+
1 2 3 4 5
31+
1 2 3 4 5
32+
5
33+
1 2 3 4 5
34+
5 4 3 4 5
35+
Example Output
36+
NO
37+
YES
38+
Explanation
39+
In both example test cases, the final radiation levels in the caves are (5,5,4,4,3). For example, the radiation power in cave 1 increased the radiation levels in caves 1 and 2 (there is no cave 0) by 1, and the radiation power in cave 4 increased the radiation levels in all caves by 1.

ZOMCAV/codechef.class

1.97 KB
Binary file not shown.

ZOMCAV/codechef.ctxt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#BlueJ class context
2+
comment0.target=codechef
3+
comment1.params=args
4+
comment1.target=void\ main(java.lang.String[])
5+
numComments=2

ZOMCAV/codechef.java

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import java.util.*;
2+
import java.io.*;
3+
class codechef
4+
{
5+
public static void main(String args[])throws IOException
6+
{
7+
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
8+
int t= Integer.parseInt(br.readLine());
9+
for(int phi=0; phi<t;phi++)
10+
{
11+
int n= Integer.parseInt(br.readLine());
12+
String ra= br.readLine();
13+
String zo= br.readLine();
14+
15+
int radpow[]= new int[n];
16+
17+
int starting[]= new int[n];
18+
19+
for(int i=0;i<n;i++)
20+
{
21+
starting[i]=0;
22+
}
23+
24+
25+
26+
StringTokenizer st = new StringTokenizer(ra);
27+
28+
int cou=0;
29+
30+
while(st.hasMoreTokens())
31+
{
32+
long val = Long.parseLong(st.nextToken());
33+
34+
int start= (int)Math.max(0, cou-val);
35+
int stop= (int)(cou+val+1);
36+
37+
38+
cou++;
39+
40+
41+
starting[start]+=1;
42+
if(stop<=n-1)
43+
starting[stop]-=1;
44+
45+
46+
}
47+
48+
49+
50+
51+
cou=0;
52+
for(int i=0;i<n;i++)
53+
{
54+
cou+=starting[i];
55+
if(cou<0)
56+
cou=0;
57+
radpow[i]+=cou;
58+
}
59+
60+
61+
62+
63+
StringTokenizer newst= new StringTokenizer(zo);
64+
65+
long xor=0;
66+
for(int i=0;i<n;i++)
67+
{
68+
xor= (xor^radpow[i])^Long.parseLong(newst.nextToken());
69+
}
70+
71+
if(xor==0)
72+
System.out.println("YES");
73+
else
74+
System.out.println("NO");
75+
}
76+
}
77+
}
78+

0 commit comments

Comments
 (0)