# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
40986 | IvanC | Sažetak (COCI17_sazetak) | C++14 | 74 ms | 40032 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5*1e6 + 10;
int pai[MAXN],peso[MAXN],N,M;
int find(int x){
if(x == pai[x]) return x;
return pai[x] = find(pai[x]);
}
void join(int x,int y){
x = find(x);
y = find(y);
if(x == y) return;
if(peso[x] < peso[y]) pai[x] = y;
else if(peso[x] > peso[y]) pai[y] = x;
else{
pai[x] = y;
peso[y]++;
}
}
int main(){
scanf("%d %d",&N,&M);
for(int i = 1;i<=N+1;i++){
pai[i] = i;
}
for(int m = 1;m<=M;m++){
int k;
scanf("%d",&k);
for(int i = 1;i<=N;i+=k){
int nxt = min(N+1,i+k);
join(i,nxt);
}
}
int ans = 0;
for(int i = 1;i<=N;i++) if(find(i) == find(i+1)) ans++;
printf("%d\n",ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |