QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#606397 | #1819. Cleaning Robot | nickbelov# | WA | 1ms | 3840kb | C++20 | 5.2kb | 2024-10-03 04:03:45 | 2024-10-03 04:03:47 |
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;
}
{ //impossible check
int need = n*m - k;
int have = 0;
queue<pii> q;
for(int i : rep(n)){
bool found = false;
for(int j : rep(m)){
if(!g[i][j]){
q.emplace(i,j);
found=true;
break;
}
}
if(found)break;
}
vii done(n,vi(m));
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;
q.emplace(nr,nc);
}
}
if(need not_eq have)
return void(cout << "-1\n");
}
//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--;
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: 0
Wrong Answer
time: 1ms
memory: 3840kb
input:
10 7 1 8 3
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2
result:
wrong answer expected '2', found '0'