Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
Problema ad-hoc, la idea de solución es simular el proceso de como va "despertando el cerebro"
**/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <cstdio>
//#define gc getchar_unlocked
using namespace std;
typedef vector<int> vi;
int B[29][29];
int W[29];
/**
void scanint(int &x)
{
register int c = gc();
x = 0;
for(;(c<48 || c>57);c = gc());
for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
}**/
int n,m,w,wp;
string s;
char b;
int main(){
int aux;
set<int> WT;//conjunto de las partes que despertaron en la ultima iteración
while(scanf("%d",&n)!=EOF){
wp=0;
w=3;
for(int i=0;i<29;i++){
for(int e=0;e<29;e++)
B[i][e]=0;
W[i]=-1;
}
scanf("%d",&m);
cin>>s;
for(int i=0;i<3;i++){
W[((int)s[i])-65]=1;
WT.insert(((int)s[i])-65);
}
for(int i=0;i<m;i++){
cin>>s;
W[((int)s[0])-65]=W[((int)s[0])-65]==-1?0:W[((int)s[0])-65];
W[((int)s[1])-65]=W[((int)s[1])-65]==-1?0:W[((int)s[1])-65];
B[((int)s[0])-65][((int)s[1])-65]=1;
B[((int)s[1])-65][((int)s[0])-65]=1;
}
int r=0;
while(w!=wp && w<n){
set<int>WTN;
wp=w;
for(int i=0;i<26;i++){
if(W[i]==0){
for(auto it=WT.begin();it!=WT.end();it++){
if(B[i][*it])
B[i][28]++;
}
if(B[i][28]>=3){
W[i]=1;
WTN.insert(i);
w++;
}
}
}
WT=WTN;
r++;
}
if(w==n)
printf("WAKE UP IN, %d, YEARS\n",r);
else
printf("THIS BRAIN NEVER WAKES UP\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.