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 "mars.h"
#include <bits/stdc++.h>
#define all(x) begin((x)), end((x))
using ll = long long;
using namespace std;
ll countIslands(bitset<100> g, ll l) {
ll ans = 0;
vector<vector<bool>> vis(101, vector<bool>(101));
for (int r = 0; r < l; r++)
for (int c = 0; c < l; c++) {
if (vis[r][c] || !g[r * l + c]) continue;
ans++;
queue<pair<ll, ll>> q;
q.push({r, c});
while (q.size()) {
ll nr = q.front().first, nc = q.front().second;
q.pop();
if (vis[nr][nc] || !g[nr * l + nc]) continue;
vis[nr][nc] = true;
for (int i = -1; i <= 1; i++)
if (nr + i >= 0 && nr + i < l && !vis[nr + i][nc]
&& g[(nr + i) * l + nc])
q.push({nr + i, nc});
for (int i = -1; i <= 1; i++)
if (nc + i >= 0 && nc + i < l && !vis[nr][nc + i]
&& g[(nr)*l + (nc + i)])
q.push({nr, nc + i});
}
}
return ans;
}
string process(vector<vector<string>> a, int i, int j, int k, int n) {
ll l = 2 * n + 1;
bitset<100> x;
for (int r = 0; r < 3; r++)
for (int c = 0; c < 3; c++) {
reverse(all(a[r][c]));
bitset<100> q(a[r][c]);
ll idx = 1 + (i + r) * l + (j + c);
x[idx] = q[0];
q[0] = 0;
x |= q;
}
if (k == n - 1) {
x >>= 1;
ll ans = countIslands(x, l);
string res = bitset<100>(ans).to_string();
reverse(all(res));
return res;
}
string s = x.to_string();
reverse(all(s));
return s;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |