Submission #476043

#TimeUsernameProblemLanguageResultExecution timeMemory
476043stefantagaSquirrel (RMI18_squirrel)C++14
10 / 100
3198 ms968 KiB
#include <bits/stdc++.h> using namespace std; long long bitmask[50005]; int mmare[50005]; int dl[]={-1,-1,0,1,1,1,0,-1}; int dc[]={0,1,1,1,0,-1,-1,-1}; bool prime(int x,int y) { if (x==1||y==1) { return true; } if (x==0||y==0) { return false; } if (bitmask[x]&bitmask[y]) { return false; } if (mmare[x]==mmare[y]&&mmare[y]>1) { return false; } return true; } long long sum=0; void fractal(int x,int y,int lung,int dir,int jum) { if (lung==0) { return; } int i; for (i=1;i<=lung;i++) { x=x+dl[dir]; y=y+dc[dir]; sum=sum+prime(x,y); } if (jum==1) { lung=lung/2; } fractal(x,y,lung,(dir+1)&7,1-jum); fractal(x,y,lung,(dir-1)&7,1-jum); } bool c[50005]; int n,m,frac,i,j,nr,x,y; int main() { cin>>n>>m>>frac; int lim=max(n,m); for (i=2;i<=lim;i++) { if (mmare[i]==0) { for (j=i;j<=lim;j+=i) { mmare[j]=i; } } } for (i=2;i*i<=lim;i++) { if (c[i]==0) { for (j=i;j<=lim;j+=i) { c[j]=1; bitmask[j]+=(1<<nr); } nr++; } } for (i=1;i<=frac;i++) { cin>>x>>y>>nr;x--;y--; sum=sum+prime(x,y); fractal(x,y,nr,0,1); } cout<<sum; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...