SNGGW - Great Warrior

no tags 

This problem is about an imaginary game. First of all, define a War Board that is a N x N square matrix. Each matrix cell represents a warrior and the value written in the cell is the power of that particular warrior.

Rules for assigning powers of each warrior

1. First start filling the main diagonal with numbers 1, 2, 3, 4 .... K according to requirement. Starting of filling always be at the top corner.
2. Now start filling the anti diagonal with numbers k + 1, k + 2, k + 3, k + 4 .... L according to requirement. Starting of filling always be at the bottom corner. Don't forget that in case of filling the anti diagonal if there is any number already filled it will be modified by the current number that is to be filled, if that particular cell was empty.
3. Now fill all the empty cells, in anti-clockwise spiral filling manner. The first cell to be filled will be 2nd last column of first row.

5 x 5 War Board

Image to describe power assignment to each cell

Description of game
The greatest warrior W of king Pushyamitra Shunga is having fight with Yavana warriors. W fights with one Yavana warrior Y at a time. Consider the followings
1. Power_of_W is more than Yavanas.
2. W can defeat Y if Power_of_W > Power_of_Y - 1
3. After each win Power_of_W decreases by Power_of_Y
4. W can move to cells adjacent to it. If Current_Cell_Location_of_W is (i, j) then
Next_Cell_Location_of_W will be one of (i ± 1, j ± 1) or (i ± 1, j) or (i, j ± 1)
5. W will win if W defeats Y such that Power_of_Y = 1, otherwise W is defeated.

What to code
You have to code to verify whether W wins or get defeated but don't forget the followings -
1. The one cell location is of W and other cell locations are of Yavanas
2. Its up to W to choose the Yavana warrior Y to fight with
3. Its not necessary that W has to defeat all Yavanas, W just want to win

[All the information required to solve this problem is provided in the description]

Input

First line of input is t, total number of test cases (t < 1001). Next t lines contains value of
N (2 < N < 1000).

Output

Output for each test case is single line printing either DWON Final_Power_of_W (If W wins) or DDOWN (If W is defeated).

Example

Input:
1
5 Output: DWON 15

hide comments
nadstratosfer: 2017-11-05 20:29:19

What an unintelligible mess of a statement.
"1. Power_of_W is more than Yavanas" - how much more? Is it n*n + 2?
"5. W will win if W defeats Y such that Power_of_Y = 1" - which one would that be? The cell with 1 is occupied by W himself.
Can W move to previously visited cells?
How is the output 15 for 5 achieved?

Bhumit: 2016-09-12 15:43:43

First to solve in Java ..
AC in one go .. :)
Easy if one thinks carefully ..

xpshekhar: 2015-12-29 01:47:45

dont try to make it complex
think logically.
10 line code in c. :)

hodobox: 2015-12-13 03:13:49

Constraints don't allow n=2, and it is not present in test cases. Also, while max t*n*n = 10^9, my O(n*n) solution passed in 0.00 :)

Siddharth Singh: 2015-11-14 08:40:30

The Problem Is Any Easy One
Solved It In 1 Go.
Just Try For n=3,4,6,7
And Yes , Dont Forget To Check n=2 .

Last edit: 2015-11-14 08:40:41
AvmnuSng: 2014-02-04 20:39:49

Read problem statement carefully

ABHISHEK: 2014-02-04 20:39:49

What is the initial location of W?


Added by:AvmnuSng
Date:2013-09-06
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Abhimanyu Singh
My Problems