Submission #854741

#TimeUsernameProblemLanguageResultExecution timeMemory
854741Tenis0206Squirrel (RMI18_squirrel)C++11
0 / 100
4798 ms600 KiB
#include <bits/stdc++.h> using namespace std; int dx[] = {-1,0,1,0}; int dy[] = {0,1,0,-1}; int m,n,f; int rez = 0; bool coprime(int x, int y) { return __gcd(x,y) == 1; } void solve(int x, int y, int s, int dir) { for(int i=1;i<=s;i++) { int xx = x + i * dx[dir]; int yy = y + i * dy[dir]; rez += coprime(xx,yy); } x = x + s * dx[dir]; y = y + s * dy[dir]; if(s==1) { return; } for(int i=1;i<=s/2;i++) { int xs = x + i * dx[dir] + i * dx[(dir + 3) % 4]; int ys = y + i * dy[dir] + i * dy[(dir + 3) % 4]; rez += coprime(xs,ys); } solve(x + (s / 2) * dx[dir] + (s / 2) * dx[(dir + 3) % 4], y + (s / 2) * dy[dir] + (s / 2) * dy[(dir + 3) % 4], s / 2, dir); solve(x + (s / 2) * dx[dir] + (s / 2) * dx[(dir + 3) % 4], y + (s / 2) * dy[dir] + (s / 2) * dy[(dir + 3) % 4], s / 2, (dir + 3) % 4); for(int i=1;i<=s/2;i++) { int xd = x + i * dx[dir] + i * dx[(dir + 1) % 4]; int yd = y + i * dy[dir] + i * dy[(dir + 1) % 4]; rez += coprime(xd,yd); } solve(x + (s / 2) * dx[dir] + (s / 2) * dx[(dir + 1) % 4], y + (s / 2) * dy[dir] + (s / 2) * dy[(dir + 1) % 4], s / 2, dir); solve(x + (s / 2) * dx[dir] + (s / 2) * dx[(dir + 1) % 4], y + (s / 2) * dy[dir] + (s / 2) * dy[(dir + 1) % 4], s / 2, (dir + 1) % 4); } int main() { ios::sync_with_stdio(false); cin.tie(0); #ifdef home freopen("nr.in","r",stdin); freopen("nr.out","w",stdout); #endif // home cin>>m>>n>>f; for(int i=1;i<=f;i++) { int x,y,s; cin>>x>>y>>s; rez += coprime(x,y); solve(x,y,s,0); } cout<<rez<<'\n'; 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...