QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#606399 | #1819. Cleaning Robot | nickbelov# | WA | 422ms | 101576kb | C++20 | 4.3kb | 2024-10-03 04:06:32 | 2024-10-03 04:06:33 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>
ostream_iterator<T> oit(const string &s = " "){ return ostream_iterator<T>(cout,s.c_str()); }
inline auto rep(int l, int r) { return views::iota(min(l, r), r); }
inline auto rep(int n) { return rep(0, n); }
inline auto rep1(int l, int r) { return rep(l, r + 1); }
inline auto rep1(int n) { return rep(1, n + 1); }
inline auto per(int l, int r) { return rep(l, r) | views::reverse; }
inline auto per(int n) { return per(0, n); }
inline auto per1(int l, int r) { return per(l, r + 1); }
inline auto per1(int n) { return per(1, n + 1); }
#define A(a) begin(a),end(a)
inline auto len = ranges::ssize;
struct chash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
template<typename T, typename U> using pb_map = gp_hash_table<T, U, chash>;
template<typename T> using pb_set = gp_hash_table<T, null_type, chash>;
#define K first
#define V second
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
typedef vector<ll> vll;
using pll = pair<ll,ll>;
using pii = pair<int,int>;
constexpr ll NN = 2e5, M = 1000000007, L = 20;
const vector<pii> delta = {{1,0},{-1,0},{0,1},{0,-1}};
void run()
{
int n,m,k; cin >> n >> m >> k;
int mx_ans = min(n,m);
vector<vll> g(n,vll(m));
for(int r,c; int _ : rep(k)){
cin >> r >> c,--r,--c;
g[r][c]=1;
}
//ans is the length of the min vertical or horizontal distance of 1 squares
for(int i : rep(n)){
int last = -1;
for(int j : rep(m)){
if(g[i][j]){
int d = j-last-1;
if(d) mx_ans = min(mx_ans,d);
last=j;
}
}
int d = m-last-1;
if(d) mx_ans = min(mx_ans,d);
}
for(int j : rep(m)){
int last = -1;
for(int i : rep(n)){
if(g[i][j]){
int d = i-last-1;
if(d) mx_ans = min(mx_ans,d);
last=i;
}
}
int d = n-last-1;
if(d) mx_ans = min(mx_ans,d);
}
auto p = g;
for(int i : rep(n)){
for(int j : rep(1,m)) p[i][j]+=p[i][j-1];
}
for(int i : rep(1,n)) for(int j : rep(m))
p[i][j] += p[i-1][j];
auto query = [&](int r,int c,int k){
if(r<k-1 or c<k-1) return 1LL; //not right
ll here = p[r][c];
if(r-k>=0) here-=p[r-k][c];
if(c-k>=0) here-=p[r][c-k];
if(r-k>=0 and c-k>=0) here+=p[r-k][c-k];
return here;
};
// for(auto &v : g)
// ranges::copy(v,oit<ll>()),cout<<endl;
auto check = [&](int k){
int need = 0,have=0;
pii start = {-1,-1};
for(int i : rep(n)) for(int j : rep(m)) if(!g[i][j] and query(i,j,k)==0)
start = {i,j},need++;
if(need==0) return false;
queue<pii> q; vii done(n,vi(m)); q.push(start);
while(not q.empty()){
auto [r,c] {q.front()}; q.pop();
if(done[r][c]) continue;
have++,done[r][c]=true;
for(int nr,nc; auto [dr,dc] : delta){
nr = dr+r,nc=dc+c;
if(nr<0 or nr>=n)continue;
if(nc<0 or nc>=m)continue;
if(done[nr][nc]) continue;
if(g[nr][nc]) continue;
if(query(nr,nc,k)) continue;
q.emplace(nr,nc);
}
}
return need==have;
};
// cout << check(2) << endl;
auto ans = *ranges::partition_point(rep1(1,mx_ans),[&](int k){ return check(k);});
ans--;
if(ans==0) ans=-1;
cout << ans << '\n';
}
int main()
{
//KING OF THE WORLD...... U.W.T.B
cin.tie(0);
ios_base::sync_with_stdio(false);
run();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
input:
10 7 1 8 3
output:
2
result:
ok answer is '2'
Test #2:
score: 0
Accepted
time: 231ms
memory: 101508kb
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:
1
result:
ok answer is '1'
Test #3:
score: 0
Accepted
time: 422ms
memory: 101576kb
input:
2236 2236 2143 228 686 129 801 1105 382 2196 1919 2082 777 1672 268 174 916 234 491 1235 274 1645 1849 1114 1173 1351 1677 1294 1365 1059 197 611 1715 1769 1395 885 1902 1190 1304 1039 779 610 124 881 662 22 1664 239 1283 2218 2031 169 1417 291 143 228 1837 1518 2013 747 359 1997 1030 73 153 614 488...
output:
3
result:
ok answer is '3'
Test #4:
score: -100
Wrong Answer
time: 212ms
memory: 101564kb
input:
2236 2236 63774 369 1861 1156 2150 1895 160 546 1944 1688 645 49 1888 430 973 1602 30 1988 971 1120 1307 322 1524 1559 1070 558 1147 973 1965 572 923 370 646 1436 1982 132 681 1410 308 1812 982 2191 2112 1311 396 1067 1330 659 477 873 881 1766 508 2091 1875 895 716 2058 1237 1374 1005 2183 1514 227 ...
output:
10
result:
wrong answer expected '8', found '10'