QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#518394 | #1819. Cleaning Robot | AA_Surely# | WA | 140ms | 159928kb | C++23 | 2.9kb | 2024-08-13 20:09:26 | 2024-08-13 20:09:26 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define FOR(i, x, n) for(int i = x; i < n; i++)
#define F0R(i, n) FOR(i, 0, n)
#define ROF(i, x, n) for(int i = n - 1; i >= x; i--)
#define R0F(i, n) ROF(i, 0, n)
#define WTF cout << "WTF" << endl
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define S second
#define PB push_back
#define EP emplace_back
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef complex<LD> Point;
const int N = 1e6 + 7;
const int INF = 1e9 + 7;
const int LOG = 22;
const int A = 26;
const int SQ = 320;
const int MOD = 1e9 + 7;
LL n, m, k;
VLL ns[N], ps[N], can[N], seen[N];
int xm[4] = {1, 0, 0,-1};
int ym[4] = {0,-1, 1, 0};
LL getPs(int i1, int j1, int i2, int j2) {
LL ret = ps[i2][j2];
if (i1) ret -= ps[i1 - 1][j2];
if (j1) ret -= ps[i2][j1 - 1];
if (i1 && j1) ret += ps[i1 - 1][j1 - 1];
return ret;
}
bool canGo(int i, int j, int l) {
//cout << " i j " <<i << ' ' << j << ' ' << l << endl;
if (i < 0 || j < 0) return 0;
if (i + l - 1 >= n || j + l - 1 >= m) return 0;
if (getPs(i, j, i + l - 1, j + l - 1)) return 0;
return 1;
}
void dfs(int x, int y, int l) {
seen[x][y] = 1;
can[x][y] = 1;
F0R(i, 4)
if (canGo(x + xm[i], y + ym[i], l) && !seen[x + xm[i]][y + ym[i]])
dfs(x + xm[i], y + ym[i], l);
return;
}
LL getCan(int i1, int j1, int i2, int j2) {
LL ret = can[i2][j2];
if (i1 > 0) ret -= can[i1 - 1][j2];
if (j1 > 0) ret -= can[i2][j1 - 1];
if (i1 > 0 && j1 > 0) ret += can[i1 - 1][j1 - 1];
return ret;
}
bool check(int x) {
F0R(i, n) F0R(j, m) can[i][j] = seen[i][j] = 0;
F0R(i, n) F0R(j, m) if (canGo(i, j, x)) {
dfs(i, j, x);
F0R(ii, n)
FOR(jj, 1, m) can[ii][jj] += can[ii][jj - 1];
FOR(ii, 1, n) F0R(jj, m)
can[ii][jj] += can[ii - 1][jj];
F0R(ii, n) F0R(jj, m) {
if (!getCan(ii - x + 1, jj - x + 1, ii, jj) && !ns[ii][jj]) {
return 0;
}
}
return 1;
}
return 1;
}
int main() {
IOS;
cin >> n >> m >> k;
F0R(i, n) {
ns[i].resize(m);
ps[i].resize(m);
seen[i].resize(m);
can[i].resize(m);
}
F0R(i, k) {
int a, b;
cin >> a >> b;
ns[--a][--b] = 1;
}
F0R(i, n) {
ps[i][0] = ns[i][0];
FOR(j, 1, m) ps[i][j] = ps[i][j - 1] + ns[i][j];
}
FOR(i, 1, n) F0R(j, m)
ps[i][j] += ps[i - 1][j];
int l = 1, r = min(n, m);
while(l < r) {
int mid = (l + r) >> 1;
if (check(mid)) l = mid + 1;
else r = mid;
}
cout << (l - 1 <= 0 ? -1 : l - 1) << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3568kb
input:
10 7 1 8 3
output:
2
result:
ok answer is '2'
Test #2:
score: -100
Wrong Answer
time: 140ms
memory: 159928kb
input:
2236 2236 2214 28 1255 389 2175 730 592 1360 977 1225 752 1403 1798 1518 1381 147 745 659 249 951 1475 1826 1951 691 1033 81 1458 1487 1946 2106 1395 1995 629 470 891 1902 822 2210 2001 441 2130 1198 1539 2027 1101 215 1149 205 420 379 2104 308 1225 859 109 1417 2078 1764 376 1772 5 335 1113 917 118...
output:
2235
result:
wrong answer expected '1', found '2235'