Last active
August 19, 2021 22:43
-
-
Save luciocf/ff605271100cc17caed5fbf18c7d5b2b to your computer and use it in GitHub Desktop.
Simulado NOIC - Segunda Fase OBI 2021
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
// 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