glow's blog

By glow, history, 3 years ago, In English

A string is called beautiful if string S = T + T. You're given a string find length of longest beautiful subsequence in given string.

Constraints : 1 <= length(S) <= 100

PS: Ihave no clue except try all numbers with k bits set and like bit-mask check if it's beautiful. Of-course you take k even and start from biggest possible k ie. length(S) - (length(S) & 1). Any hints on this ?

Read more »

 
 
 
 
  • Vote: I like it
  • +16
  • Vote: I do not like it

By glow, history, 3 years ago, In English

Hi, I am trying to solve a question. I understand the basic approach here using inclusion-exclusion principle but not able to understand what's happening in code at line 54 to 70. I understand that author of code is trying to place digits in empty places but why one loop(for i) starts from 0 and end at <dig_n-1 and why reverse after that(line 61) ? and similar kind of thing with j loop.

Problem editorial: here

Code take from here

Read more »

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

By glow, history, 5 years ago, In English

Hi, I was solving Hard Problem and my approach is :

If string[i] <= string[i+1] than continue;

Else :

    If  string_rev[i] < string[i+1] c1=cost[i] Else c1=inf;

    If string[i] < string_rev[i+1] c2=cost[i+1] Else c2=inf;

    If string_rev[i] < string_rev[i+1] c3=cost[i]+cost[i+1]; Else c3=inf;

    if(c1<=c2 && c1<=c3 && c1!=inf) ans+=c1; If(c1==c2)a[i+1]=min(a[i+1],b[i+1]);;

    else if(c2<=c1 && c2<=c3 && c2!=inf) ans+=c2; a[i+1]=min(a[i+1],b[i+1]);

    else if(c3<=c1 && c3<=c2 && c3!=inf) ans+=c3; a[i+1]=min(a[i+1],b[i+1]);

Code Link.

Can you please help me in finding fault in this approach ?

Read more »

 
 
 
 
  • Vote: I like it
  • -1
  • Vote: I do not like it

By glow, 6 years ago, In English

Hi, can anyone please tell me how to declare a 2-D array like following ->

long int arr[1000000100][1000000100];

ie. the problem is that row and column sizes are too large. I tried following but it gave segmentation fault :

const long int maxi=1000000100;

long int **mat;

void doit(){

mat=(long int **)malloc(maxi*sizeof(long int *));

for(long int z=0;z<maxi;z++)

mat[z]=(ll *)malloc(maxi*sizeof(long int *));

}

Complete code -> http://pastebin.com/R0rrVCK4

ThankYou. :)

Read more »

 
 
 
 
  • Vote: I like it
  • -24
  • Vote: I do not like it

By glow, 6 years ago, In English

On 26-March I had a coding round for Internship. Following were the 2 problems in that round :

Q1-> http://pastebin.com/KWjT8nJq

Q2-> http://pastebin.com/sa9VJkZF

My solution to question:

1-> http://pastebin.com/gzsDRNZK (RESULT : wrong answer)

In 2nd question naive solution gave TLE.

Can anyone please suggest new approaches or what test cases my code failed[Q1].

Thanks.

Read more »

 
 
 
 
  • Vote: I like it
  • +5
  • Vote: I do not like it