Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5b68774

Browse files
Merge pull request #77 from Sushank34/master
Added more Lunchtime codes and a long challenge codes to Codechef
2 parents d705ef8 + f50b3b4 commit 5b68774

27 files changed

+2529
-0
lines changed
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import java.util.*;
2+
import java.lang.*;
3+
import java.io.*;
4+
5+
class Codechef
6+
{
7+
static class FastReader
8+
{
9+
BufferedReader br;
10+
StringTokenizer st;
11+
12+
public FastReader()
13+
{
14+
br = new BufferedReader(new
15+
InputStreamReader(System.in));
16+
}
17+
18+
String next()
19+
{
20+
while (st == null || !st.hasMoreElements())
21+
{
22+
try
23+
{
24+
st = new StringTokenizer(br.readLine());
25+
}
26+
catch (IOException e)
27+
{
28+
e.printStackTrace();
29+
}
30+
}
31+
return st.nextToken();
32+
}
33+
34+
int nextInt()
35+
{
36+
return Integer.parseInt(next());
37+
}
38+
39+
40+
long nextLong()
41+
{
42+
return Long.parseLong(next());
43+
}
44+
45+
double nextDouble()
46+
{
47+
return Double.parseDouble(next());
48+
}
49+
50+
String nextLine()
51+
{
52+
String str = "";
53+
try
54+
{
55+
str = br.readLine();
56+
}
57+
catch (IOException e)
58+
{
59+
e.printStackTrace();
60+
}
61+
return str;
62+
}
63+
}
64+
public static void main(String[] args) throws java.lang.Exception{
65+
FastReader sc=new FastReader();
66+
int t=sc.nextInt();
67+
while(t-->0) {
68+
String s=sc.next();
69+
int[] zero=new int[s.length()];
70+
int[] ones=new int[s.length()];
71+
zero[s.length()-1]=s.length();
72+
if(s.charAt(s.length()-1)=='0') {
73+
zero[s.length()-1]--;
74+
}
75+
for(int i=s.length()-2;i>=0;i--) {
76+
zero[i]=zero[i+1];
77+
if(s.charAt(i)=='0') {
78+
zero[i]=i;
79+
}
80+
}
81+
if(zero[0]==s.length()) {
82+
System.out.print("0\n");
83+
continue;
84+
}
85+
ones[s.length()-1]=s.length();
86+
if(s.charAt(s.length()-1)=='1') {
87+
ones[s.length()-1]--;
88+
}
89+
for(int i=s.length()-2;i>=0;i--) {
90+
ones[i]=ones[i+1];
91+
if(s.charAt(i)=='1') {
92+
ones[i]=i;
93+
}
94+
}
95+
int[] dp=new int[s.length()+1];
96+
int[] dp1=new int[s.length()+1];
97+
for(int i=s.length()-1;i>=0;i--) {
98+
dp[i]=dp[i+1];
99+
dp1[i]=dp1[i+1];
100+
if(s.charAt(i)=='0'&&ones[i]<s.length()) {
101+
dp[i]=Math.max(dp[i],dp[ones[i]+1]+1);
102+
}
103+
if(s.charAt(i)=='1'&&zero[i]<s.length()) {
104+
dp[i]=Math.max(dp[i],dp[zero[i]+1]+1);
105+
}
106+
if(ones[i]<s.length()) {
107+
dp1[i]=Math.max(dp1[i],dp[ones[i]+1]+1);
108+
}
109+
}
110+
int ind=ones[0]+1,ind2=dp1[0]+1;
111+
int[] res=new int[s.length()];
112+
res[0]=1;
113+
int resl=1;
114+
for(int i=1;i<ind2;i++) {
115+
if(ind>=s.length()) {
116+
res[resl++]=0;
117+
continue;
118+
}
119+
if(zero[ind]>=s.length()) {
120+
ind=zero[ind]+1;
121+
res[resl++]=0;
122+
continue;
123+
}
124+
if(dp[zero[ind]+1]<ind2-i-1) {
125+
ind=zero[ind]+1;
126+
res[resl++]=0;
127+
}
128+
else {
129+
ind=ones[ind]+1;
130+
res[resl++]=1;
131+
}
132+
}
133+
for(int i=0;i<resl;i++) {
134+
System.out.print(res[i]);
135+
}
136+
System.out.print("\n");
137+
}
138+
}
139+
}

‎Codechef/APRIL21B/Chef and Dice.java

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import java.util.*;
2+
import java.lang.*;
3+
import java.io.*;
4+
5+
class Codechef
6+
{
7+
static class FastReader
8+
{
9+
BufferedReader br;
10+
StringTokenizer st;
11+
12+
public FastReader()
13+
{
14+
br = new BufferedReader(new
15+
InputStreamReader(System.in));
16+
}
17+
18+
String next()
19+
{
20+
while (st == null || !st.hasMoreElements())
21+
{
22+
try
23+
{
24+
st = new StringTokenizer(br.readLine());
25+
}
26+
catch (IOException e)
27+
{
28+
e.printStackTrace();
29+
}
30+
}
31+
return st.nextToken();
32+
}
33+
34+
int nextInt()
35+
{
36+
return Integer.parseInt(next());
37+
}
38+
39+
40+
long nextLong()
41+
{
42+
return Long.parseLong(next());
43+
}
44+
45+
double nextDouble()
46+
{
47+
return Double.parseDouble(next());
48+
}
49+
50+
String nextLine()
51+
{
52+
String str = "";
53+
try
54+
{
55+
str = br.readLine();
56+
}
57+
catch (IOException e)
58+
{
59+
e.printStackTrace();
60+
}
61+
return str;
62+
}
63+
}
64+
public static void main(String[] args) throws java.lang.Exception{
65+
FastReader sc=new FastReader();
66+
int t=sc.nextInt();
67+
while(t-->0) {
68+
long n=sc.nextLong();
69+
if(n<=4) {
70+
if(n==1){
71+
System.out.print("20\n");
72+
}
73+
if(n==2){
74+
System.out.print("36\n");
75+
}
76+
if(n==3){
77+
System.out.print("51\n");
78+
}
79+
if(n==4){
80+
System.out.print("60\n");
81+
}
82+
}
83+
else {
84+
if(n%4==0){
85+
System.out.print( ( ( ((n-n%4)/4) *44) +16) +"\n");
86+
}
87+
else if(n%4==1){
88+
System.out.print( ( ( ((n-n%4)/4) *44) +32) +"\n");
89+
}
90+
else if(n%4==2){
91+
System.out.print( ( ( ((n-n%4)/4) *44) +44) +"\n");
92+
}
93+
else if(n%4==3){
94+
System.out.print( ( ( ((n-n%4)/4) *44) +55) +"\n");
95+
}
96+
}
97+
}
98+
}
99+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /