Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("ai.in");
- ofstream fout("ai.out");
- int n, k, a, b, m[1010][1010], v[1010][1010], d_x, d_y, c, y, rez[1010][1010];
- int tx, ty, s1x, s1y, s2x, s2y, r1x, r1y, r2x, r2y;
- int di[4] = {-1, 0, 1, 0};
- int dj[4] = {0, 1, 0, -1};
- vector<pair<int,int>> d1, d2;
- void lee(int i, int j)
- {
- queue<pair<int, int>> q;
- memset(rez, 0, sizeof(rez));
- rez[i][j] = 1;
- q.push({i, j});
- while(!q.empty())
- {
- i = q.front().first;
- j = q.front().second;
- q.pop();
- for(int k = 0; k < 4; k++)
- {
- int ni = i + di[k];
- int nj = j + dj[k];
- if(m[ni][nj] == 0 && rez[ni][nj] == 0)
- {
- rez[ni][nj] = rez[i][j] + 1;
- q.push({ni, nj});
- }
- }
- }
- }
- int lmax_lin(int i)
- {
- int lcrt = 0, lmax = INT_MIN;
- for(int j = 1; j <= n; j++)
- {
- if(m[i][j] == -1)
- lcrt++;
- else
- {
- lmax = max(lcrt, lmax);
- lcrt = 0;
- }
- }
- lmax = max(lcrt, lmax);
- return lmax;
- }
- int lmax_col(int j)
- {
- int lcrt = 0, lmax = INT_MIN;
- for(int i = 1; i <= n; i++)
- {
- if(m[i][j] == -1)
- lcrt++;
- else
- {
- lmax = max(lcrt, lmax);
- lcrt = 0;
- }
- }
- lmax = max(lcrt, lmax);
- return lmax;
- }
- void gard(int n, int k)
- {
- for(int i = 0; i <= n+1; i++)
- m[i][0] = m[i][k+1] = -1;
- for(int j = 0; j <= k+1; j++)
- m[0][j] = m[n+1][j] = -1;
- }
- void pct_dr(int tx, int sx, int sy, vector<pair<int,int>> &d)
- {
- int d_x = abs(tx - sx);
- int d_y = abs(ty - sy);
- int c = __gcd(d_x, d_y);
- d_x /= c;
- d_y /= c;
- if(sx < tx)
- for(int x = sx; x != tx; x += d_x)
- y += d_y, v[x][y] = 1, d.push_back({x,y});
- else
- {
- y = sy;
- for(int x = sx; x != tx; x -= d_x)
- d.push_back({x,y}), v[x][y] = 1, y -= d_y;
- }
- }
- int dreapta_robot(vector<pair<int,int>> d)
- {
- int minim = INT_MAX;
- for(int i = 0; i < d.size(); i++)
- {
- int a = rez[d[i].first][d[i].second];
- if(a && a < minim)
- minim = a;
- }
- return minim-1;
- }
- int main()
- {
- fin >> n;
- fin >> tx >> ty >> s1x >> s1y >> s2x >> s2y >> r1x >> r1y >> r2x >> r2y;
- gard(n, n);
- fin >> k;
- for (int i = 1; i <= k; i++)
- fin >> a >> b, m[a][b] = -1;
- int lz = INT_MIN;
- for(int i = 1; i <= n; i++)
- lz = max(lz, lmax_lin(i));
- for(int j = 1; j <= n; j++)
- lz = max(lz, lmax_col(j));
- fout << lz << '\n';
- m[tx][ty] = -1;
- pct_dr(tx, s1x, s1y, d1);
- pct_dr(tx, s2x, s2y, d2);
- lee(r1x, r1y);
- int dr1_r1 = dreapta_robot(d1);
- //cout << dr1_r1 << ' ' ;
- int dr2_r1 = dreapta_robot(d2);
- //cout << dr2_r1 << '\n';
- lee(r2x, r2y);
- int dr1_r2 = dreapta_robot(d1);
- //cout << dr1_r2 << ' ' ;
- int dr2_r2 = dreapta_robot(d2);
- //cout << dr2_r2 << '\n' ;
- int m1 = max(dr1_r1, dr2_r2);
- int m2 = max(dr2_r1, dr1_r2);
- if(m1 < m2)
- fout << m1;
- else
- fout << m2;
- fin.close();
- fout.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement