Submission #40986

#TimeUsernameProblemLanguageResultExecution timeMemory
40986IvanCSažetak (COCI17_sazetak)C++14
64 / 160
74 ms40032 KiB
#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)

sazetak.cpp: In function 'int main()':
sazetak.cpp:21:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&N,&M);
                      ^
sazetak.cpp:27:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&k);
                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...