Created
July 13, 2021 17:03
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
constexpr int maxn = 110; | |
// salvamos os vetores indicando qual foi a ultima mensagem, a soma atual e se há alguma mensagem pendente ou não | |
int ans[maxn], ultima[maxn], atv[maxn]; | |
int main() { | |
// t representa o tempo atual que estamos simulando | |
int n, t = 1; scanf("%d", &n); | |
bool ok = 0; | |
for(int i = 0; i < n; i++) { | |
// lemos o tipo do evento que nos é dado | |
char c; int x; scanf(" %c %d", &c, &x); | |
// se for um evento do tipo T só adicionamos o tempo dado na resposta | |
if(c == 'T') t += x, ok = 0; | |
// evento de tipo R | |
else if(c == 'R') { | |
// se o evento anterior foi do tipo T não adicionamos nada no tempo, senao adicionamos 1 | |
t += ok; ok = 1; | |
// salvamos qual o tempo da última mensagem enviada e dizemos que existe uma mensagem pendente | |
ultima[x] = t; | |
atv[x] = 1; | |
} else { // evento do tipo E | |
// mudamos o tempo como fizemos no tipo R | |
t += ok; ok = 1; | |
// adicionamos na resposta para esse amigo a diferença entre os tempos de envio e resposta | |
ans[x] += t - ultima[x]; | |
// marcamos como não havendo nenhuma mensagem pendente | |
atv[x] = 0; | |
} | |
} | |
for(int i = 1; i <= 100; i++) { | |
if(ultima[i]) { // checo se esse indice de amigo recebeu alguma mensagem em qualquer momento | |
printf("%d ", i); | |
if(atv[i]) printf("-1\n"); // se existe alguma mensagem pendente printo -1 | |
else printf("%d\n", ans[i]); // senao printo o tempo de resposta | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment