B. Lawnmower

Rate this post

The Lawnmower is the problem B of the Google Code Jam 2013 Qualification round.

The suggested solution in the Contest analysis is to try to cut grace on every row and column to the maximum height found on this row or column then compare the pattern got with the pattern given.

My approach is different. For any given cell on the lawn we can detect is there a cell with bigger height on a way to the border (we check for all four directions), if so we can't not cut on this direction to achieve desired pattern. The advantage of this solution is that we can detect negative answer much quicker.

Here is my solution for this problem in C language:


#include <stdio.h>

main() {
  int i, T, M, N, n, m, x;
  int res;

  scanf("%d\n", &T);
  for (i = 0; i < T; i++) {
    printf("Case #%d: ", i + 1);
    scanf("%d %d\n", &N, &M);
    {
      int L[N][M];
      res = 1;
      for (n = 0; n < N; n++) {
	for (m = 0; m < M; m++) {
	  scanf("%d", &L[n][m]);
	}
      }
      for (n = 0; n < N && res; n++) {
	for (m = 0; m < M && res; m++) {
	  int res1 = 1, res2 = 1, res3 = 1, res4 = 1;
	  for (x = m - 1; x >= 0 && res1; x--) if (L[n][m] < L[n][x]) res1 = 0;
	  for (x = m + 1; x < M && res2; x++) if (L[n][m] < L[n][x]) res2 = 0;
	  if ((res1 + res2) != 2) {
	    for (x = n - 1; x >= 0 && res3; x--) if (L[n][m] < L[x][m]) res3 = 0;
	    for (x = n + 1; x < N && res4; x++) if (L[n][m] < L[x][m]) res4 = 0;
	  }
	  if ((res1 == 1 && res2 == 1) || (res3 == 1 && res4 == 1)) {
	    res = 1;
	  } else res = 0;
	}
      }
      if (res) printf("YES\n");
      else printf("NO\n");
    }
  }
}

0 thoughts on “B. Lawnmower

  1. JsgfmRuxnf

    Typically recent blemish, Identical to the hen house blemish, That permit you to make an individual's desired form of transport sound ready. Specifically watching our short-term telecasting a suggestion for you to observe how to enjoy the form of transport settled blemish for this popular wow(03/09/10). It an uncomplicated blemish in the rooms that aids you to use a form of transport this is uncomplete to earn a stable 100% and also from using it collect. louboutin pas cher
    Not too people around the globe created a three year unique conjunction having straight talk check out the. You start with universe S4, They created a build-your-own Sohu video footage practical application which is before placed in straight talk china's websites on the road tools. Along the next many years, Most people foresee that more than 100 million straight talk units, Along with mobiles as well medication, Should have all of your practical application before set, louboutin pas cher
    With to consider place(Virtual martial arts styles, Pertaining to private computer, $49.99, On 30 times of online times), Maker Funcom carries a launched a mythological digital eco booming featuring haunted is home to, Unknown organizations, Creature of the night cults and / or zombie invasions that experts claim comes across as being completely distinctive line of up including other sorts of books during sort appreciate the widely admired wow transformers: The existing Republic.Some offerings come from big apple, London, uk or columbia, Counting on wheyou see, our ownr employees make the decision to join covert Illuminati, Templar and / or maybe monster groups. For the other hand, Basically barely is important on account fans of any and all ilk are usually almost instantly sent having a black colored location of the latest uk someplace people delve further into single or along with even so tasks.The sphere also offers you digarded a common flair arrangement for characteristics decided by tools for example shotguns, Swords, Strike weapons or mystical text magazines. Guitar musicians can sometimes activate two at that time with earnings along with seven hectic additionally unaggressive understanding. louboutin pas cher
    So does it boast worthwhile? Easily, That's exactly completely up to you. Has it been difficult the person that likesstrategywows? Can waiting moreover later pay the full price on behalf of three episodic programs? Do you need to participate or possibly have fun with playing just for entertainment? I in a position method a lot of such issues in your. I let you know despite the fact that if you will want begin weather conditions an individual not used to this mmorpg or provide played spend less you may be with regard to anexperiencethat isn't in the near future avoid, louboutin pas cher
    Just that use acquire around the tour shuttle in HS. They got by inside along with to the harmful. I get bad mum designation but unfortunately 5:30 isn't on offered radar, When i often aren't required to be to any place proper 9:00. Specific cast's union is great, In particular in relation to Ko and so Aoba, Who is spoken fighting almost all sour retorts and straightforward biology shattered by the rare peek at the sentimental icebergs the key and gnaruntruthst currently Wakaba those underneath the luxurious top health from the relaxing intimate loving broken working love. For no reason comes with the"Bickering couple" Been lately through more complete. Now we have expanded to enjoy and consequently maintain this type of cartoon figures, These people, A long way the direction they love and then attend to some other, It really is essentially series' superb joys purely to spending some time throughout their workplace, louboutin pas cher

    you may also like:
    http://richlinked.com/index.php?do=/profile-6624/info/ http://www.lclfmceastrome.it/joomla/index.php?option=com_phocaguestbook&view=phocaguestbook&id=1&Itemid=18 http://punbb.123flashchat.com/profile.php?id=468590

Leave a Reply

Your email address will not be published. Required fields are marked *