QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#276743#4170. 猪国杀SoyTony100 ✓2ms4108kbC++1412.3kb2023-12-06 10:15:062023-12-06 10:15:06

Judging History

你现在查看的是最新测评结果

  • [2023-12-06 10:15:06]
  • 评测
  • 测评结果:100
  • 用时:2ms
  • 内存:4108kb
  • [2023-12-06 10:15:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

int n,m;
char Ch[3];

queue<char> Deck;

int Count_Identities[4];
int Count_Players;
int Previous_Player[11],Next_Player[11];
inline void Erase_Player(int Player_Number){
    Next_Player[Previous_Player[Player_Number]]=Next_Player[Player_Number];
    Previous_Player[Next_Player[Player_Number]]=Previous_Player[Player_Number];
    --Count_Players;
}

struct PLAYER{
    int Identity,Current_Identity;
    int HP;
    bool Dead;
    int Card_Queue_Head,Card_Queue_Tail,Count_Cards;
    int Previous_Card[2005],Next_Card[2005];
    char Card_Type[2005];
    bool K_Played,Z_Played;
    inline void Input();
    inline void Get_Card();
    inline void Erase_Card(int Card_Number);
    inline void Check_Dead(int Player_Number,int Source_Player_Number);
    inline void Output_Cards();
    inline bool P_Play(int Card_Number);
    inline bool K(int Player_Number,int Card_Number);
    inline bool K_Play();
    inline bool D_Play();
    inline bool F_Check(int Player_Number,int Card_Number);
    inline void F_Play(int Player_Number,int Source_Player_Number);
    inline bool N(int Player_Number,int Card_Number);
    inline bool W(int Player_Number,int Card_Number);
    inline int J_Check(int Player_Number,int Source_Player_Number,bool Type);
    inline bool J_Play(int Player_Number);
    inline bool Z(int Player_Number);
    inline void Play(int Player_Number);
}Player[11];

inline void PLAYER::Input(){
    scanf("%s",Ch);
    if(Ch[0]=='M') Identity=1;
    else if(Ch[0]=='Z') Identity=2;
    else Identity=3;
    ++Count_Identities[Identity];
    Current_Identity=0;
    HP=4;
    Dead=false;
    Card_Queue_Head=1,Card_Queue_Tail=4,Count_Cards=4;
    for(int i=1;i<=4;++i){
        scanf("%s",Ch);
        Previous_Card[i]=i-1,Next_Card[i]=i+1;
        Card_Type[i]=Ch[0];
    }
    Previous_Card[1]=-1,Next_Card[4]=-1;
    K_Played=false,Z_Played=false;
}
inline void PLAYER::Get_Card(){
    ++Count_Cards;
    Card_Type[Count_Cards]=Deck.front();
    Previous_Card[Count_Cards]=Card_Queue_Tail,Next_Card[Count_Cards]=-1;
    if(Card_Queue_Tail!=-1) Next_Card[Card_Queue_Tail]=Count_Cards;
    else Card_Queue_Head=Count_Cards;
    Card_Queue_Tail=Count_Cards;
    if((int)Deck.size()>1) Deck.pop(); 
}
inline void PLAYER::Erase_Card(int Card_Number){
    if(Card_Number==Card_Queue_Head) Card_Queue_Head=Next_Card[Card_Number];
    else Next_Card[Previous_Card[Card_Number]]=Next_Card[Card_Number];
    if(Card_Number==Card_Queue_Tail) Card_Queue_Tail=Previous_Card[Card_Number];
    else Previous_Card[Next_Card[Card_Number]]=Previous_Card[Card_Number];
}
inline void PLAYER::Check_Dead(int Player_Number,int Source_Player_Number){
    --HP;
    if(HP) return;
    for(int i=Card_Queue_Head;i!=-1;i=Next_Card[i]){
        if(Card_Type[i]!='P') continue;
        P_Play(i);
        return;        
    }
    Dead=true;
    --Count_Identities[Identity];
    Erase_Player(Player_Number);
    if(!Count_Identities[3]){
        printf("MP\n");
        for(int i=1;i<=n;++i){
            if(Player[i].Dead) printf("DEAD\n");
            else Player[i].Output_Cards();
        }
        exit(0);
    }
    else if(!Count_Identities[1]){
        printf("FP\n");
        for(int i=1;i<=n;++i){
            if(Player[i].Dead) printf("DEAD\n");
            else Player[i].Output_Cards();
        }
        exit(0);
    }
    if(Identity==3){
        Player[Source_Player_Number].Get_Card(),Player[Source_Player_Number].Get_Card(),Player[Source_Player_Number].Get_Card();
    }
    else if(Player[Source_Player_Number].Identity==1&&Identity==2){
        Player[Source_Player_Number].Card_Queue_Head=Player[Source_Player_Number].Card_Queue_Tail=-1;
        Player[Source_Player_Number].Z_Played=false;
    }
}
inline void PLAYER::Output_Cards(){
    for(int i=Card_Queue_Head;i!=-1;i=Next_Card[i]) printf("%c ",Card_Type[i]);
    printf("\n");
}
inline bool PLAYER::P_Play(int Card_Number){
    if(HP<4){
        ++HP;
        Erase_Card(Card_Number);
        return true;
    }
    else return false;
}
inline bool PLAYER::K(int Player_Number,int Card_Number){
    if(K_Played&&!Z_Played) return false;
    if(Identity==1&&(Player[Next_Player[Player_Number]].Current_Identity==2||Player[Next_Player[Player_Number]].Current_Identity==3)){
        Erase_Card(Card_Number);
        bool D_Played=Player[Next_Player[Player_Number]].D_Play();
        if(!D_Played) Player[Next_Player[Player_Number]].Check_Dead(Next_Player[Player_Number],Player_Number);
    }
    else if(Identity==2&&Player[Next_Player[Player_Number]].Current_Identity==2){
        Erase_Card(Card_Number);
        bool D_Played=Player[Next_Player[Player_Number]].D_Play();
        if(!D_Played) Player[Next_Player[Player_Number]].Check_Dead(Next_Player[Player_Number],Player_Number);
        Current_Identity=1;
    }
    else if(Identity==3&&(Player[Next_Player[Player_Number]].Identity==1||Player[Next_Player[Player_Number]].Current_Identity==1)){
        Erase_Card(Card_Number);
        bool D_Played=Player[Next_Player[Player_Number]].D_Play();
        if(!D_Played) Player[Next_Player[Player_Number]].Check_Dead(Next_Player[Player_Number],Player_Number);
        Current_Identity=2;
    }
    else return false;
    K_Played=true;
    return true;
}
inline bool PLAYER::K_Play(){
    for(int i=Card_Queue_Head;i!=-1;i=Next_Card[i]){
        if(Card_Type[i]!='K') continue;
        Erase_Card(i);
        return true;
    }
    return false;
}
inline bool PLAYER::D_Play(){
    for(int i=Card_Queue_Head;i!=-1;i=Next_Card[i]){
        if(Card_Type[i]!='D') continue;
        Erase_Card(i);
        return true;
    }
    return false;
}
inline bool PLAYER::F_Check(int Player_Number,int Card_Number){
    if(Identity!=3){
        for(int i=Next_Player[Player_Number];i!=Player_Number;i=Next_Player[i]){
            if(
                (Identity==1&&(Player[i].Current_Identity==2||Player[i].Current_Identity==3))||
                (Identity==2&&Player[i].Current_Identity==2)){
                Current_Identity=1;
                Erase_Card(Card_Number);
                F_Play(i,Player_Number);
                return true;
            }
        }
    }
    else{
        Current_Identity=2;
        Erase_Card(Card_Number);
        F_Play(1,Player_Number);
        return true;
    }
    return false;
}
inline void PLAYER::F_Play(int Player_Number,int Source_Player_Number){
    bool Type=false;
    int Temporary_Source_Player_Number=Source_Player_Number;
    while(1){
        int J_Played=Player[Player_Number].J_Check(Player_Number,Source_Player_Number,Type);
        if(!J_Played) break;
        Source_Player_Number=J_Played,Type^=1;
    }
    if(Type) return;
    Source_Player_Number=Temporary_Source_Player_Number;
    bool Turn=false;
    while(1){
        if(!Turn){
            bool FK_Played;
            if(Identity==1&&Player[Player_Number].Identity==2) FK_Played=false;
            else FK_Played=Player[Player_Number].K_Play();
            if(!FK_Played){
                Player[Player_Number].Check_Dead(Player_Number,Source_Player_Number);
                return;
            }
        }
        else{
            bool FK_Played;
            if(Player[Player_Number].Identity==1&&Identity==2) FK_Played=false;
            else FK_Played=K_Play();
            if(!FK_Played){
                Check_Dead(Source_Player_Number,Player_Number);
                return;
            }
        }
        Turn^=1;
    }
}
inline bool PLAYER::N(int Player_Number,int Card_Number){
    Erase_Card(Card_Number);
    int Source_Player_Number;
    for(int i=Next_Player[Player_Number];i!=Player_Number;i=Next_Player[i]){
        bool Type=false;
        Source_Player_Number=Player_Number;
        while(1){
            int J_Played=Player[i].J_Check(i,Source_Player_Number,Type);
            if(!J_Played) break;
            Source_Player_Number=J_Played,Type^=1;
        }
        if(Type) continue;
        Source_Player_Number=Player_Number;
        bool NK_Played=Player[i].K_Play();
        if(!NK_Played){
            if(Player[i].Identity==1&&!Current_Identity) Current_Identity=3;
            Player[i].Check_Dead(i,Source_Player_Number);
        }
    }
    return true;
}
inline bool PLAYER::W(int Player_Number,int Card_Number){
    Erase_Card(Card_Number);
    int Source_Player_Number;
    for(int i=Next_Player[Player_Number];i!=Player_Number;i=Next_Player[i]){
        bool Type=false;
        Source_Player_Number=Player_Number;
        while(1){
            int J_Played=Player[i].J_Check(i,Source_Player_Number,Type);
            if(!J_Played) break;
            Source_Player_Number=J_Played,Type^=1;
        }
        if(Type) continue;
        Source_Player_Number=Player_Number;
        bool WD_Played=Player[i].D_Play();
        if(!WD_Played){
            if(Player[i].Identity==1&&!Current_Identity) Current_Identity=3;
            Player[i].Check_Dead(i,Source_Player_Number);
        }
    }
    return true;
}
inline int PLAYER::J_Check(int Player_Number,int Source_Player_Number,bool Type){
    if(Identity!=1&&Current_Identity!=1&&Current_Identity!=2) return 0;
    bool Source_Player_Visited=false;
    for(int i=Source_Player_Number;;i=Next_Player[i]){
        if(i==Source_Player_Number){
            if(Source_Player_Visited) return 0;
            else Source_Player_Visited=true;
        }
        if(!Type){
            if(
                (Identity==1&&(Player[i].Identity==1||Player[i].Identity==2))||
                (Current_Identity==1&&(Player[i].Identity==1||Player[i].Identity==2))){
                bool J_Played=Player[i].J_Play(i);
                if(J_Played){
                    Player[i].Current_Identity=1;
                    return i;
                } 
            }
            else if(Current_Identity==2&&Player[i].Identity==3){
                bool J_Played=Player[i].J_Play(i);
                if(J_Played){
                    Player[i].Current_Identity=2;
                    return i;
                } 
            }
        }
        else{
            if(
                (Identity==1&&Player[i].Identity==3)||
                (Current_Identity==1&&Player[i].Identity==3)){
                bool J_Played=Player[i].J_Play(i);
                if(J_Played){
                    Player[i].Current_Identity=2;
                    return i;
                } 
            }
            else if(
                (Current_Identity==2&&(Player[i].Identity==1||Player[i].Identity==2))||
                (Current_Identity==3&&Player[i].Identity==1)){
                bool J_Played=Player[i].J_Play(i);
                if(J_Played){
                    Player[i].Current_Identity=1;
                    return i;
                } 
            }
        }
    }
}
inline bool PLAYER::J_Play(int Player_Number){
    for(int i=Card_Queue_Head;i!=-1;i=Next_Card[i]){
        if(Card_Type[i]!='J') continue;
        Erase_Card(i);
        return true;
    }
    return false;
}
inline bool PLAYER::Z(int Card_Number){
    Z_Played=true;
    Erase_Card(Card_Number);
    return true;
}

inline void PLAYER::Play(int Player_Number){
    Get_Card(),Get_Card();
    K_Played=false;
    int Count=0;
    while(1){
        ++Count;
        bool Played=false;
        for(int i=Card_Queue_Head;i!=-1;i=Next_Card[i]){
            if(Card_Type[i]=='P') Played=P_Play(i);
            else if(Card_Type[i]=='K') Played=K(Player_Number,i);
            else if(Card_Type[i]=='F') Played=F_Check(Player_Number,i);
            else if(Card_Type[i]=='N') Played=N(Player_Number,i);
            else if(Card_Type[i]=='W') Played=W(Player_Number,i);
            else if(Card_Type[i]=='Z') Played=Z(i);
            else continue;
            if(Played) break;
        }
        if(Dead) break;
        if(!Played) break;
    }
}

int main(){
    scanf("%d%d",&n,&m);
    Count_Players=n;
    for(int i=1;i<=n;++i) Player[i].Input();
    for(int i=1;i<=m;++i){
        scanf("%s",Ch);
        Deck.push(Ch[0]);
    }
    for(int i=1;i<=n;++i) Previous_Player[i]=i-1,Next_Player[i]=i+1;
    Previous_Player[1]=n,Next_Player[n]=1;
    int Current_Player=1;
    while(1){
        Player[Current_Player].Play(Current_Player);
        Current_Player=Next_Player[Current_Player];
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 2ms
memory: 3868kb

input:

5 2000
MP K K P P
FP D K D K
ZP P P D K
FP D K P D
FP P K P P
D D D P D K P P D D P D D K P P D P D P P K K P D P K D P P D Z P P P K P P D P K K Z K K P D K K P D Z K D P D P K P P K K D P P K P P P P K P K P D K K D P D K D P K Z K K K K D D K K Z P K D D P K P D K Z K P P P K D P K P K K P K Z D ...

output:

FP
DEAD
D K D K D P D K K P P P K K D D P K P P K K K P K D P D D K D P K D D K D P K D P K K P P D K D P P K K P D K P P K K P D P D K D D P K K D P K D P D D D K P K D K D D P P D K P K K P P D P K K P P K D D K D K D P K P K P P D K D D D P P K K K K P K P K K K D D K K P D D P D D K D K D K D K ...

result:

ok 6 lines

Test #2:

score: 5
Accepted
time: 0ms
memory: 3768kb

input:

2 2000
MP P P K K
FP D Z K D
D D Z P K D P P Z D K D P P P D P K D P K Z K K K D D K D D D D D D Z D P D K P P P K P P Z K P P P P P Z D D K P D P Z D D P K Z P P K D K K Z K K P K D K P P D D D K D D D P K K D Z K P D P D P P P D D D K P D D K P K D D K K K D D P D D D K D K P P K Z K D D D D K D D...

output:

MP

DEAD

result:

ok 3 lines

Test #3:

score: 5
Accepted
time: 0ms
memory: 3876kb

input:

5 2000
MP D F W D
FP W N P N
ZP P F P K
FP D K P P
FP F D K K
D P F P K D P K D D F K F P P D K K N Z K D W D F D K K P K W N F N F W W N K F K W D N P P K P F F W P F N K F K D D K N N N F K N K N D D P K P K K W N F N W W K F N P D W F K K W D N W K D N K F F W N W P N K Z N P K P W N N W K K N P ...

output:

FP
DEAD
P 
K D 
P K 
D D 

result:

ok 6 lines

Test #4:

score: 5
Accepted
time: 0ms
memory: 4056kb

input:

5 2000
MP P K K K
FP N W K P
FP F K K F
FP Z F P W
ZP W F D P
P F P D K K F F P W N D P P W F W P N P D N D F N K D F F P F D K N F W F F P W W K D N P K D N F K F D W N K W K D N P P F P N K K D D N K P F F P N N D D D D D D W F Z D K W K W P N D K P W P W D W P W W W P F P D W P W P D F N W W K D ...

output:

FP
DEAD
K P P 
K 
F 
W F P 

result:

ok 6 lines

Test #5:

score: 5
Accepted
time: 0ms
memory: 3776kb

input:

5 2000
MP N F F P
FP F K F N
ZP P F K F
ZP F W W W
ZP F D D F
K K D N N F P P F P P N F N W F F N F W N D N N N K P K D N P K P N N F W D D W W K P N F D W K K K N N N W F D W N K N F P D P K N P N D Z K F P K D W N P F K W N N F D P K K F D P N N N N P F D W F N W K D N N W N N F P W P N P K D K P ...

output:

MP
F F P 
DEAD
N F 
F W W W 
F D D F 

result:

ok 6 lines

Test #6:

score: 5
Accepted
time: 0ms
memory: 3732kb

input:

5 2000
MP F F K K
ZP P F W D
FP F D K W
FP K P F N
ZP Z F N K
F W W W F F W N N W D W W F P K K N K N K N D P K K W K P W P W W N P N D D W F W N N N N Z D D W N P F K N N K Z K P N W K F K F D D K W K W P W P P W W D N D N W P D N D N K F W N K N K F K N W D F K K K K K F D P W Z F D K D F N D F K ...

output:

FP
DEAD
P F 
DEAD
F N W D 
DEAD

result:

ok 6 lines

Test #7:

score: 5
Accepted
time: 0ms
memory: 3828kb

input:

7 2000
MP J P W F
ZP F D D D
ZP F D J J
FP K W P P
FP F K F W
ZP W N J N
FP N W N K
K F J D J P N F J F W J P N D D D J K P N P F N W K W J W K J D D N K P D W K K J Z W K Z W F F D J K J F N W J J K P J P K J P N F P J K F F N K K F J K N F D D D K K P P P F P P J K K J W J N W D P N K D J D D K K ...

output:

FP
DEAD
F 
DEAD
P 
DEAD
P N D D D 
DEAD

result:

ok 8 lines

Test #8:

score: 5
Accepted
time: 0ms
memory: 3752kb

input:

7 2000
MP W K D F
FP F J D N
FP J K F D
ZP F N W K
FP W N P N
FP P D P K
FP J K Z N
P W W F F K F K K N D F P F J P J J N N N W Z K J W D J D N D D D J N N J P D W J K K F P P D D F J P F D P K W W D K N K P P N D N D K J D N P N D K K P D J N P P K K N N K P W J F K D D D F F J P D D D P K F P N W ...

output:

FP
DEAD

J K 
W F K K N D 
DEAD
P P 
Z N 

result:

ok 8 lines

Test #9:

score: 5
Accepted
time: 0ms
memory: 3864kb

input:

7 2000
MP K W P J
FP J K W J
FP F F W D
ZP D K Z F
ZP J P K D
ZP K J J F
FP K K J K
D N F J K F J W J D D K N N W N N J W K D N P F K W W D K W F J F D P D F D W P D P N P N N W Z D W N F D W N W P P W W Z K P P K K D K P N K W Z D F D W P Z F F W K P N J K N P W J K J P N N K J F K W F K W D D D J ...

output:

FP
DEAD
DEAD
K 
D D K N 
P 
DEAD
DEAD

result:

ok 8 lines

Test #10:

score: 5
Accepted
time: 0ms
memory: 4044kb

input:

7 2000
MP J K K D
ZP F K F N
FP F D J W
FP N D J W
ZP J F P P
FP D F N Z
ZP F N K Z
P F J J J W F N P J W P K D D P N F N W D D D W F K N J J N N F N F W D N N W P F N P J P W F F K P D W D K K P F D N P K J D K K F F K F W W F F J J P W W F K J K J F W W J D P J J W K D F F P K K D W P W F D F D P ...

output:

MP
P P N F N W 
DEAD
DEAD
DEAD

DEAD
DEAD

result:

ok 8 lines

Test #11:

score: 5
Accepted
time: 0ms
memory: 3860kb

input:

7 2000
MP F D F W
ZP W W J F
FP P F P K
ZP P F P K
FP F F K F
ZP F N J D
ZP W W D F
W P F P D F K J J D F N J J K J K D W N P W W W F N K D K N P D N N J D J N J Z W K K N F F W P P P D P W P P D D K N F N F J W J D W N K F J P K P J D J P J D F P J N J D J N W W N K P F D D P N F N N F D F W W K K ...

output:

MP
F F P 
F F F K 
DEAD
K 
DEAD
DEAD
F K 

result:

ok 8 lines

Test #12:

score: 5
Accepted
time: 0ms
memory: 4084kb

input:

7 2000
MP F K F J
FP N K K P
FP W J K W
FP N P D W
FP K F N K
FP J W F D
ZP J D F J
F W K J J W W F F J W D N F D Z D D W W W Z D K W F P F P W K N N W F F D K D P J N F J J K K J K D J J W J K P N P J D W W N N F P J N K K F K P P N J F P J P N J N F W N D N P J W N W K J J D F D D F F D D D D F N ...

output:

FP
DEAD
K K K 
F F W D 
DEAD
DEAD
W F 
DEAD

result:

ok 8 lines

Test #13:

score: 5
Accepted
time: 0ms
memory: 3888kb

input:

7 2000
MP D K K D
ZP F P N F
FP D D J K
FP D D F F
ZP W F P N
ZP D Z P D
ZP J J D P
J P N J K W N F N D D N P K N N P F P P W D W D W D P J P P W N K W D J F F K W J D D P D J P F W W P J K F W J J N W F J K F W P F F W N F D K D F K W N K D P D P D N N D K W J P F N F J D K K W F P P P W F N D F K ...

output:

MP
P N D D 
P 
DEAD
DEAD
N P 
Z P 
P 

result:

ok 8 lines

Test #14:

score: 5
Accepted
time: 0ms
memory: 3776kb

input:

10 2000
MP J J P P
ZP D J J P
ZP J K K N
FP J D N K
ZP J N K P
FP K N D J
ZP J W W N
FP P F W J
ZP K W D N
ZP W Z N K
N P K D K P K W J N W W F K D D J W D P W J P D D N F N F F J W P K P K W D Z J J P D D J N W K N K K K D P D N N J N D K K W P K W N D D P F F J W P P K P K W D W J K P J P K F W J ...

output:

MP
P P 


DEAD
W F K D D 
DEAD
DEAD
DEAD
DEAD
DEAD

result:

ok 11 lines

Test #15:

score: 5
Accepted
time: 0ms
memory: 4108kb

input:

10 2000
MP K N W W
FP W J K N
ZP D J D W
ZP N P J J
FP F N J F
ZP K P J P
FP P P K J
FP W N P F
ZP W W J P
ZP F K N N
N W D W N N N J F K N N K D N W F N D W D P K W N D K K J F F D W P P D D D K D F W N P D F F D P N J F P D P D D N F J F K K F F N K J W P P F F F W D J W J N J D P F D K W N J D F ...

output:

MP

DEAD
K 
DEAD
DEAD
DEAD
DEAD
DEAD
DEAD
DEAD

result:

ok 11 lines

Test #16:

score: 5
Accepted
time: 0ms
memory: 3848kb

input:

3 24
MP K K K K
ZP Z Z Z Z
FP J J J J
K K Z Z J J K K W Z W W K Z J J K K J J K K W W

output:

FP
DEAD
DEAD
J J J J J J J J J J W 

result:

ok 4 lines

Test #17:

score: 5
Accepted
time: 0ms
memory: 4104kb

input:

10 2000
MP J P J Z
ZP J J N J
ZP F N N P
ZP F W J Z
ZP P D D P
ZP F W J W
ZP K Z P W
FP J J J J
FP J J K J
FP J J Z J
Z N J K Z W N J N J N J J K Z F P K K J D Z W W N W Z Z J J J J J J J K N D J N Z J D D J N Z J Z J N J J P J P K N J N N J D J K Z K K K Z F F N J P P N N F Z J J P W Z J K W K D W ...

output:

MP
P 

N N J N J 
DEAD
D P 
DEAD
Z W 
DEAD
DEAD
DEAD

result:

ok 11 lines

Test #18:

score: 5
Accepted
time: 0ms
memory: 4068kb

input:

10 2000
MP K W Z Z
FP N K K K
ZP N P N J
FP J Z J K
ZP J W K D
ZP N P K P
ZP J P F J
ZP J N N W
ZP J K J W
ZP J Z K J
Z P D J D K W F F Z N J F F J K J J J J J K W D Z K N Z W K D P Z F J F P K J J W J F P F J J N F J D D P J Z J W F W J J J P W J J W J F D W J W W J D Z N F J F N W Z J D F J J J F ...

output:

MP
P 
DEAD
D 
DEAD
Z N 
N 
DEAD
DEAD
DEAD
DEAD

result:

ok 11 lines

Test #19:

score: 5
Accepted
time: 0ms
memory: 3776kb

input:

3 2000
MP F F F F
ZP N K K K
FP J J D F
F D K K K J P D J P W N J Z J J W J D W J J P K Z K N J P N F N W D J J W F J W W N P J K J N P J K J W D D Z F J P F P K P J J W D J J F N J J F K J F D D J J F W J J W Z D D F P Z J W P D D F J P W F J J W J Z N N J J F Z N D Z F J N K J J Z Z K N J P P P N ...

output:

FP
DEAD
DEAD
D 

result:

ok 4 lines

Test #20:

score: 5
Accepted
time: 0ms
memory: 4104kb

input:

10 2000
MP N K K K
FP F F F F
ZP Z J J J
FP N J J J
ZP D J Z F
FP D J K J
FP J W J W
FP J D N J
FP J D P W
ZP D F K J
F Z N J D J J F J Z J Z N K K J Z J D K N Z P W Z K P N Z J D D N N Z P W J K F F K K W J F J J J J N W P P F J K P Z N J J D D W D J K J D J W K D Z K Z Z W N Z F F J Z W D W J P J ...

output:

FP
DEAD
DEAD
DEAD
DEAD

K K 
D K 
N Z P W Z 
DEAD
DEAD

result:

ok 11 lines