# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
402532 |
2021-05-11T22:47:55 Z |
rqi |
Furniture (JOI20_furniture) |
C++14 |
|
438 ms |
12228 KB |
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define sz(x) (int)(x).size()
const int mx = 1005;
int N, M;
bool C[mx][mx];
bool disap[mx][mx];
pi deg[mx][mx];//leftup, rightdown degree
queue<pi> to_remove;
int maxrow[mx];
int maxcol[mx];
void subDeg(int X, int Y, bool typ){
if(C[X][Y] || disap[X][Y]) return;
if(mp(X, Y) == mp(1, 1) || mp(X, Y) == mp(N, M)) return;
if(typ == 0){
deg[X][Y].f--;
}
else{
deg[X][Y].s--;
}
if(deg[X][Y].f == 0 || deg[X][Y].s == 0){
to_remove.push(mp(X, Y));
disap[X][Y] = 1;
}
}
void removeToRemoves(){
while(sz(to_remove)){
pi coor = to_remove.front();
to_remove.pop();
disap[coor.f][coor.s] = 0;
C[coor.f][coor.s] = 1;
subDeg(coor.f-1, coor.s, 1);
subDeg(coor.f, coor.s-1, 1);
subDeg(coor.f+1, coor.s, 0);
subDeg(coor.f, coor.s+1, 0);
}
}
void updateMaxes(int X, int Y){
while(maxrow[X]+1 <= M){
if(C[X][maxrow[X]+1]){
maxrow[X]++;
continue;
}
else{
break;
}
}
while(maxcol[Y]+1 <= N){
if(C[maxcol[Y]+1][Y]){
maxcol[Y]++;
continue;
}
else{
break;
}
}
}
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> N >> M;
for(int i = 1; i <= N; i++){
for(int j = 1; j <= M; j++){
cin >> C[i][j];
}
}
for(int i = 0; i <= N+1; i++){
C[i][0] = C[i][M+1] = 1;
}
for(int i = 0; i <= M+1; i++){
C[0][i] = C[N+1][i] = 1;
}
for(int i = 1; i <= N; i++){
for(int j = 1; j <= M; j++){
if(mp(i, j) == mp(1, 1) || mp(i, j) == mp(N, M)) continue;
if(C[i][j]) continue;
deg[i][j].f+=(int)(!C[i-1][j])+(int)(!C[i][j-1]);
deg[i][j].s+=(int)(!C[i+1][j])+(int)(!C[i][j+1]);
if(deg[i][j].f == 0 || deg[i][j].s == 0){
to_remove.push(mp(i, j));
disap[i][j] = 1;
}
}
}
int Q;
cin >> Q;
for(int i = 1; i <= Q; i++){
//cout << "QUERY: " << i << "\n";
int X, Y;
cin >> X >> Y;
removeToRemoves();
updateMaxes(X+1, Y+1);
// for(int i = 1; i <= N; i++){
// for(int j = 1; j <= M; j++){
// cout << C[i][j] << " ";
// }
// cout << "\n";
// }
// cout << "\n";
// for(int i = 1; i <= N; i++){
// for(int j = 1; j <= M; j++){
// cout << deg[i][j].f << " ";
// }
// cout << "\n";
// }
// cout << "\n";
// for(int i = 1; i <= N; i++){
// for(int j = 1; j <= M; j++){
// cout << deg[i][j].s << " ";
// }
// cout << "\n";
// }
// cout << "\n";
if(C[X][Y] == 0 && maxrow[X+1] >= Y-1 && maxcol[Y+1] >= X-1){
cout << 0 << "\n";
}
else{
cout << 1 << "\n";
if(C[X][Y] == 0){
to_remove.push(mp(X, Y));
disap[X][Y] = 1;
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
716 KB |
Output is correct |
2 |
Correct |
2 ms |
972 KB |
Output is correct |
3 |
Correct |
3 ms |
844 KB |
Output is correct |
4 |
Correct |
4 ms |
972 KB |
Output is correct |
5 |
Correct |
6 ms |
972 KB |
Output is correct |
6 |
Correct |
6 ms |
972 KB |
Output is correct |
7 |
Correct |
6 ms |
1024 KB |
Output is correct |
8 |
Correct |
5 ms |
972 KB |
Output is correct |
9 |
Correct |
5 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
716 KB |
Output is correct |
2 |
Correct |
2 ms |
972 KB |
Output is correct |
3 |
Correct |
3 ms |
844 KB |
Output is correct |
4 |
Correct |
4 ms |
972 KB |
Output is correct |
5 |
Correct |
6 ms |
972 KB |
Output is correct |
6 |
Correct |
6 ms |
972 KB |
Output is correct |
7 |
Correct |
6 ms |
1024 KB |
Output is correct |
8 |
Correct |
5 ms |
972 KB |
Output is correct |
9 |
Correct |
5 ms |
972 KB |
Output is correct |
10 |
Correct |
14 ms |
972 KB |
Output is correct |
11 |
Correct |
4 ms |
716 KB |
Output is correct |
12 |
Correct |
227 ms |
10680 KB |
Output is correct |
13 |
Correct |
103 ms |
9844 KB |
Output is correct |
14 |
Correct |
364 ms |
11152 KB |
Output is correct |
15 |
Correct |
394 ms |
11112 KB |
Output is correct |
16 |
Correct |
377 ms |
11500 KB |
Output is correct |
17 |
Correct |
402 ms |
11968 KB |
Output is correct |
18 |
Correct |
406 ms |
11596 KB |
Output is correct |
19 |
Correct |
403 ms |
12228 KB |
Output is correct |
20 |
Correct |
438 ms |
12100 KB |
Output is correct |
21 |
Correct |
429 ms |
12124 KB |
Output is correct |