이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int ldir[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int cdir[8] = { 0, 1, 1, 1, 0, -1, -1, -1};
int ans;
bool gcd(int a, int b) {
// cout << a + 1 << ' ' << b + 1 << endl;
return (__gcd(a, b) == 1);
}
void generateFractal(int l, int c, int dir, int size) {
if(size == 0)
return;
//cout << "tree : " << endl;
for(int i = 0; i < size; i++) {
l += ldir[dir];
c += cdir[dir];
ans += gcd(l, c);
}
//cout << endl;
int dir1 = (dir - 1 + 8) % 8, dir2 = (dir + 1) % 8;
int l1 = l, c1 = c;
//cout << dir1 << " Branch 1 : " << endl;
for(int i = 0; i < size / 2; i++) {
l1 += ldir[dir1];
c1 += cdir[dir1];
ans += gcd(l1, c1);
}
// cout << dir2 << " Branch 2 : " << endl;
int l2 = l, c2 = c;
for(int i = 0; i < size / 2; i++) {
l2 += ldir[dir2];
c2 += cdir[dir2];
ans += gcd(l2, c2);
}
// cout << endl << endl;
generateFractal(l1, c1, (dir1 - 1 + 8) % 8, size / 2);
generateFractal(l1, c1, (dir1 + 1 + 8) % 8, size / 2);
generateFractal(l2, c2, (dir2 - 1 + 8) % 8, size / 2);
generateFractal(l2, c2, (dir2 + 1 + 8) % 8, size / 2);
}
int main() {
int m, n, f;
cin >> m >> n >> f;
ans = 0;
for(int i = 0; i < f; i++) {
int l, c, size;
cin >> l >> c >> size;
l--;
c--;
ans += gcd(l, c);
generateFractal(l, c, 0, size);
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |