QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#32555 | #4170. 猪国杀 | Qingyu | 100 ✓ | 3ms | 1964kb | C++23 | 9.8kb | 2022-05-21 13:13:25 | 2022-05-21 13:13:26 |
Judging History
answer
/*
* Task: Killer Of Pig Kingdom
* Submitter: Qingyu Shi
* Submit Time: 2019.02.24 09:02:32
* Verdict: OK
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
const int MAX_CARD = 2050;
const int N = 25;
struct Player {
int count, hp, nxt, prv;
char identify, cards[MAX_CARD];
bool army;
} a[N];
char cardSet[MAX_CARD], identify[N]; // 'U' = unknown
int n, nowCard, totalCard, agCount;
bool missionFinished;
inline void getNewCard(int playerID) {
if (nowCard == totalCard)
--nowCard;
a[playerID].cards[++a[playerID].count] = cardSet[++nowCard];
}
inline void clear(int playerID) {
a[playerID].count = 0;
a[playerID].army = false;
memset(a[playerID].cards, 0, sizeof a[playerID].cards);
}
inline void killPlayer(int playerID, int attackerID) {
// Try use 'P'
for (int j = 1; j <= a[playerID].count; ++j) {
if (a[playerID].cards[j] == 'P') {
a[playerID].cards[j] = 0;
a[playerID].hp++;
return;
}
}
// Change dis.
a[a[playerID].prv].nxt = a[playerID].nxt;
a[a[playerID].nxt].prv = a[playerID].prv;
// Check
if (a[playerID].identify == 'M') {
missionFinished = true; // Mission failed!
return;
}
if (a[playerID].identify == 'F') {
--agCount;
if (agCount == 0) { // Mission complete!
missionFinished = true;
return;
}
getNewCard(attackerID);
getNewCard(attackerID);
getNewCard(attackerID);
}
if (a[playerID].identify == 'Z' && a[attackerID].identify == 'M')
clear(attackerID);
}
inline void attack(int playerID, int attackerID) {
// Try use D
for (int j = 1; j <= a[playerID].count; ++j)
if (a[playerID].cards[j] == 'D') {
a[playerID].cards[j] = 0;
return;
}
--a[playerID].hp;
// Try killPlayer.
if (a[playerID].hp == 0)
killPlayer(playerID, attackerID);
}
inline bool unattackable(int playerID, int targetID, int mode) {
bool flag = true;
for (int i = playerID; i != playerID || flag; i = a[i].nxt) {
flag = false;
if (mode == 1) {
if ((a[i].identify == identify[targetID]) || (a[i].identify == 'Z' && identify[targetID] == 'M') ||
(a[i].identify == 'M' && identify[targetID] == 'Z')) {
for (int j = 1; j <= a[i].count; ++j) {
if (a[i].cards[j] == 'J') {
a[i].cards[j] = 0;
identify[i] = a[i].identify;
return !unattackable(i, playerID, !mode);
}
}
}
} else {
if (((a[i].identify == 'Z' || a[i].identify == 'M') && identify[playerID] == 'F') || (a[i].identify == 'F' &&
(identify[playerID] == 'Z' || identify[playerID] == 'M'))) {
for (int j = 1; j <= a[i].count; ++j) {
if (a[i].cards[j] == 'J') {
a[i].cards[j] = 0;
identify[i] = a[i].identify;
return !unattackable(i, playerID, mode);
}
}
}
}
}
return false;
}
inline void invasion(int playerID, char key) {
for (int i = a[playerID].nxt; i != playerID; i = a[i].nxt) {
if (unattackable(playerID, i, 1) == false) {
int j = 0;
for (j = 1; j <= a[i].count; ++j) {
if (a[i].cards[j] == key) {
a[i].cards[j] = 0;
break;
}
}
if (j > a[i].count) {
--a[i].hp;
if (i == 1 && identify[playerID] == 0)
identify[playerID] = 'L';
if (a[i].hp == 0)
killPlayer(i, playerID);
if (missionFinished)
return;
}
}
}
}
inline void fight(int playerID, int attackerID) {
if (unattackable(attackerID, playerID, 1) == false) {
if (attackerID == 1 && a[playerID].identify == 'Z') {
--a[playerID].hp;
if (a[playerID].hp == 0)
killPlayer(playerID, attackerID);
} else {
int j = 1, k = 1;
while (true) {
while (j <= a[playerID].count && a[playerID].cards[j] != 'K')
++j;
if (j <= a[playerID].count)
a[playerID].cards[j] = 0;
else {
--a[playerID].hp;
if (a[playerID].hp == 0)
killPlayer(playerID, attackerID);
break;
}
while (k <= a[attackerID].count && a[attackerID].cards[k] != 'K')
++k;
if (k <= a[attackerID].count)
a[attackerID].cards[k] = 0;
else {
--a[attackerID].hp;
if (a[attackerID].hp == 0)
killPlayer(attackerID, playerID);
break;
}
}
}
}
}
inline char *outCards(int i) {
char ans[MAX_CARD];
int k = 0;
for (int j = 1; j <= a[i].count; ++j) {
if (a[i].cards[j] != 0)
ans[k++] = a[i].cards[j];
}
return ans;
}
inline void gameStart() {
missionFinished = false;
if (agCount == 0)
return;
bool flag = false;
for (int i = 1; i; i = a[i].nxt) {
if (i == 2)
flag = true;
getNewCard(i);
getNewCard(i);
bool attacked = false;
for (int j = 1; j <= a[i].count; ++j)
if (a[i].cards[j] != 0) {
if (a[i].hp == 0)
break;
char thisCard = a[i].cards[j];
if (thisCard == 'P' && a[i].hp < 4) {
++a[i].hp;
a[i].cards[j] = 0;
} else if (thisCard == 'K' && (a[i].army == true || attacked == false)) {
if (a[i].identify == 'Z' && identify[a[i].nxt] != 'F')
continue;
if (a[i].identify == 'M' && identify[a[i].nxt] != 'F' && identify[a[i].nxt] != 'L')
continue;
if (a[i].identify == 'F' && identify[a[i].nxt] != 'Z' && identify[a[i].nxt] != 'M')
continue;
a[i].cards[j] = 0;
attack(a[i].nxt, i);
attacked = true;
identify[i] = a[i].identify;
if (missionFinished == true)
return;
} else if (thisCard == 'F') {
if (a[i].identify == 'F') { // Attack 'M' first.
a[i].cards[j] = 0;
fight(1, i);
identify[i] = 'F';
if (missionFinished)
return;
j = 0; // Recheck 'P'
} else {
for (int k = a[i].nxt; k != i; k = a[k].nxt) { // Find first 'F' or 'L'
if ((a[i].identify == 'Z' && identify[k] == 'F') || (a[i].identify == 'M' && (identify[k] == 'L' ||
identify[k] == 'F'))) {
a[i].cards[j] = 0;
fight(k, i);
identify[i] = a[i].identify;
if (missionFinished)
return;
j = 0; // Recheck 'P'
break;
}
}
}
} else if (thisCard == 'Z') {
a[i].army = true;
a[i].cards[j] = 0;
j = 0; // Recheck 'K'
} else if (thisCard == 'W') {
a[i].cards[j] = 0;
invasion(i, 'D');
if (missionFinished)
return;
j = 0;
} else if (thisCard == 'N') {
a[i].cards[j] = 0;
invasion(i, 'K');
if (missionFinished)
return;
j = 0;
}
}
}
}
inline void Init() {
// Init player list
for (int i = 1; i <= n; ++i)
a[i].nxt = i + 1, a[i].prv = i - 1;
a[n].nxt = 1, a[1].prv = n;
// Read player data
static char buf[1000005];
for (int i = 1; i <= n; ++i) {
scanf("%s", buf); // Read bus. ID
a[i].identify = buf[0];
for (int j = 1; j <= 4; ++j) {
scanf("%s", buf); // Read card ID
a[i].cards[j] = buf[0];
}
a[i].count = a[i].hp = 4;
if (a[i].identify == 'F')
++agCount;
}
identify[1] = 'M';
for (int i = 1; i <= totalCard; ++i) {
scanf("%s", buf);
cardSet[i] = buf[0];
}
}
inline void gameEnd() {
puts(a[1].hp <= 0 ? "FP" : "MP");
for (int i = 1; i <= n; ++i) {
if (a[i].hp <= 0)
puts("DEAD");
else {
for (int j = 1; j <= a[i].count; ++j)
if (a[i].cards[j] != 0)
printf("%c ", a[i].cards[j]);
printf("\n");
}
}
}
int main() {
scanf("%d %d", &n, &totalCard);
Init();
gameStart();
gameEnd();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 2ms
memory: 1800kb
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: 3ms
memory: 1832kb
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: 1756kb
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: 1744kb
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: 1748kb
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: 1ms
memory: 1748kb
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: 1ms
memory: 1760kb
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: 1ms
memory: 1704kb
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: 1ms
memory: 1768kb
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: 1ms
memory: 1832kb
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: 1ms
memory: 1832kb
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: 1ms
memory: 1828kb
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: 1ms
memory: 1840kb
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: 1ms
memory: 1760kb
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: 1ms
memory: 1780kb
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: 1ms
memory: 1964kb
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: 1ms
memory: 1836kb
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: 1ms
memory: 1824kb
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: 1ms
memory: 1700kb
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: 1ms
memory: 1832kb
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