1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <cstring> #include <vector> #define init(x) memset (x,-1,sizeof (x)) #define ll long long #define ull unsigned long long #define INF 0x3f3f3f3f using namespace std; const int MAX = 1e5 + 5; const int MOD = 1e9 + 7; inline int read (); vector <pair <int,int> > v; int t,outa,outb,cnt; int a[25][25],vis[25][25],sx[] = {0,0,1,-1},sy[] = {1,-1,0,0}; void search (int x,int y,int col); int main () { t = read ();init (a); for (int i = 1;i <= t;++i) { int x = read (),y = read (),ty = (i & 1) ? 0 : 1; a[x][y] = ty;outa = outb = 0;
for (int i = 0;i < 4;++i) { int xx = x + sx[i],yy = y + sy[i]; cnt = 0;v.clear (); if (1 <= xx && xx <= 19 && 1 <= yy && yy <= 19) { if (a[xx][yy] == (ty ^ 1) && !vis[xx][yy]) search (xx,yy,ty ^ 1); if (!cnt) { if (ty == 0) outb += v.size (); else outa += v.size (); for (auto p : v) a[p.first][p.second] = -1; } } } cnt = 0;v.clear (); search (x,y,ty); if (!cnt) { if (ty == 0) outa += v.size (); else outb += v.size (); for (auto p : v) a[p.first][p.second] = -1; } for (int i = 1;i <= 19;++i) for (int j = 1;j <= 19;++j) vis[i][j] = 0; printf ("%d %d\n",outa,outb); } return 0; } inline int read () { int s = 0;int f = 1; char ch = getchar (); while ((ch < '0' || ch > '9') && ch != EOF) { if (ch == '-') f = -1; ch = getchar (); } while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0'; ch = getchar (); } return s * f; } void search (int x,int y,int col) { vis[x][y] = 1;v.push_back ({x,y}); for (int i = 0;i < 4;++i) { int xx = x + sx[i],yy = y + sy[i]; if (1 <= xx && xx <= 19 && 1 <= yy && yy <= 19) { if (a[xx][yy] == -1) ++cnt; if (a[xx][yy] == col && !vis[xx][yy]) search (xx,yy,col); } } }
|