A. PENTA KILL!
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
OLO's global tournament, ISM, is in full swing and Shizuku is a big fan of GNR which is taking part in the tournament. OLO is a game where two teams of five players play against each other. PENTA KILL is considered an unbelievable achievement in the game, which means one player kills five pairwise distinct opponents in a row. We assume that a player will be resurrected immediately after his death, and the death will not affect the verdict of his PENTA KILL.
Normally, PENTA KILL will be displayed in the game. However, sometimes due to unintended disparity in latency between competing teams, it is not displayed properly in the game. After the game, Shizuku gets a chronological list of kills during the game. She wants to know whether a player has achieved PENTA KILL in this game.
Input
The first line contains an integer nn (1≤n≤10001≤n≤1000), indicating the number of kills in the game.
Each of the following nn lines contains two strings aa and bb consisting of English letters and digital numbers, indicating that the player named aa kills the player named bb. The length of each string won't exceed 100100. It is guaranteed that there are no kills between teammates and there are exactly five players per team.
Output
Output PENTA KILL! if a player has achieved PENTA KILL, or SAD:( otherwise.
Examples
input
Copy
10 Bin Guigo Grevthar Bin GALA Grevthar GALA TitaN GALA Guigo GALA Aegis GALA Jojo GALA Grevthar Xiaohu Grevthar GALA Aegis
output
Copy
PENTA KILL!
input
Copy
7 GALA Jojo GALA Jojo Aegis GALA GALA Grevthar GALA Aegis GALA Guigo GALA TitaN
output
Copy
PENTA KILL!
input
Copy
7 GALA Jojo Aegis Ming GALA Grevthar GALA Grevthar GALA Aegis GALA Guigo GALA TitaN
output
Copy
SAD:(
Note
In the second sample, GALA kills Jojo, Grevthar, Aegis, Guigo, and TitaN in a row so he gets PENTA KILL.
In the third sample, GALA kills Grevthar twice after he kills Jojo so he doesn't kill five distinct opponents in a row.
思路:按照题意的话,意思是只要有一个人 连续击杀对面五个人不重复即算五杀
注意在这中间,这个人可以被杀掉,因为这里规定了复活时间是0s。所以只需要枚举出现过5次的人,然后看他是否杀了5个不同的人,用set去维护,当人数大于5人了出现重复,还是算做五杀(不知道是否可以理解为虐泉),当set中的人数不足5人然后重复的话,说明有一个人被杀了多次,即不是五杀了!
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define rep(i,a,n) for (int i = a; i < n; i ++ )
#define repn(i,a,n) for (int i = a; i <= n; i ++ )
#define pb push_back
#define pb push
typedef long long ll;
typedef pair<int,int> PII;
ll gcd(ll a,ll b) { return b ? gcd(b,a % b) : a; }
int main()
{
int n;
cin >> n;
string a[n + 1], b[n + 1];
map<string, int> s;
for (int i = 0; i < n; i ++ )
{
cin >> a[i] >> b[i];
s[a[i]] ++;
}
bool flag = false;
for (int i = 0; i < n; i ++ )
{
if(s[a[i]] < 5) continue;
else
{
set<string> v;
for (int j = i; j < n; j ++ )
{
if(a[j] == a[i])
{
if(v.find(b[j]) == v.end())
v.insert(b[j]);
else if(v.find(b[j]) != v.end() && v.size() >= 5)
{
break;
}
else if(v.find(b[j]) != v.end() && v.size () < 5)
{
v.clear();
break;
}
}
}
if(v.size() >= 5){
flag = true;
}
}
}
if(flag){
cout << "PENTA KILL!" << endl;
}else{
cout << "SAD:(" << endl;
}
return 0;
}