# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
464099 | CyberCow | T-Covering (eJOI19_covering) | C++17 | 2 ms | 716 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <iterator>
#include <stack>
using namespace std;
using ll = long long;
int v[1002][1002];
int a[1002][1002];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m, i, j, x, y, k, asn;
ll ans = 0;
cin >> n >> m;
for ( i = 1; i <= n; i++)
{
for ( j = 1; j <= m; j++)
{
cin >> v[i][j];
}
}
cin >> k;
for ( i = 0; i < k; i++)
{
cin >> x >> y;
a[x][y] = 1;
}
if (a[1][1] == 1 || a[1][m] == 1 || a[n][1] == 1 || a[n][m] == 1)
{
cout << "No";
exit(0);
}
for ( i = 1; i <= n; i++)
{
for ( j = 1; j < m; j++)
{
if (a[i][j] == 1 && a[i - 1][j] == 1)
{
if (i + 1 <= n && i - 2 >= 1 && j > 1 && j < m)
{
ans += a[i][j] + a[i][j + 1] + a[i][j - 1] + a[i + 1][j];
}
else
{
cout << "No";
exit(0);
}
}
else if (a[i][j] == 1 && a[i + 1][j] == 1)
{
if (i + 2 <= n && i - 1 >= 1 && j > 1 && j < m)
{
ans += a[i][j] + a[i][j + 1] + a[i][j - 1] + a[i - 1][j];
}
else
{
cout << "No";
exit(0);
}
}
else if (a[i][j] == 1 && a[i][j + 1] == 1)
{
if (i + 1 <= n && i - 1 >= 1 && j - 1 >= 1 && j + 2 <= m)
{
ans += a[i][j] + a[i][j - 1] + a[i + 1][j] + a[i - 1][j];
}
else
{
cout << "No";
exit(0);
}
}
else if (a[i][j] == 1 && a[i][j - 1] == 1)
{
if (i + 1 <= n && i - 1 >= 1 && j - 2 >= 1 && j + 1 <= m)
{
ans += a[i][j] + a[i][j + 1] + a[i + 1][j] + a[i - 1][j];
}
else
{
cout << "No";
exit(0);
}
}
else
{
ans += a[i][j] + a[i][j + 1] + a[i + 1][j] + a[i - 1][j] + a[i][j - 1] - min(min(a[i][j - 1], a[i - 1][j]), min(a[i][j + 1], a[i + 1][j]));
}
}
}
return 0;
}
Compilation message (stderr)
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |