Skip to content

Instantly share code, notes, and snippets.

@luciocf
Last active August 19, 2021 22:43
Show Gist options
  • Save luciocf/ff605271100cc17caed5fbf18c7d5b2b to your computer and use it in GitHub Desktop.
Save luciocf/ff605271100cc17caed5fbf18c7d5b2b to your computer and use it in GitHub Desktop.
Simulado NOIC - Segunda Fase OBI 2021
// Simulado NOIC - Segunda Fase - OBI 2021
// Operações
// Complexidade: O(N + M)
// Escrito por Lúcio Figueiredo
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6+10;
bool mark[maxn]; // vetor de marcação
int main(void)
{
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
int x;
scanf("%d", &x);
mark[x] = 1; // marcamos 1 se x está no vetor
}
int ans = 0; // resposta do problema
// iteramos por todos os possíveis valores
for (int i = 1; i < maxn; i++)
if (mark[i]) // se i está marcado, encontramos mais um valor do vetor
ans++;
printf("%d\n", ans);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment