Submission #476042

#TimeUsernameProblemLanguageResultExecution timeMemory
476042stefantagaSquirrel (RMI18_squirrel)C++14
0 / 100
2983 ms964 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; for (i=2;i<=50000;i++) { if (mmare[i]==0) { for (j=i;j<=50000;j+=i) { mmare[j]=i; } } } for (i=2;i*i<=50000;i++) { if (c[i]==0) { for (j=i;j<=50000;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...