답안 #423570

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
423570 2021-06-11T09:35:34 Z Kerim Furniture (JOI20_furniture) C++17
100 / 100
488 ms 15756 KB
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;
 
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N=1002;
int vis[N][N],dgn[N+N],n,m;
stack<PII>st;
void upd(int x,int y){
	if(!vis[x][y]){
		dgn[x+y]--;
		vis[x][y]=1;
		st.push(mp(x,y));
	}
}
void check(int x,int y){
	if(vis[x][y] and vis[x+1][y-1]){
		upd(x,y-1);
		upd(x+1,y);
	}
}
int mark(int x,int y){
	if(vis[x][y])return 1;
	if(dgn[x+y]==1)return 0;
	upd(x,y);
	while(!st.empty()){
		int x=st.top().ff;
		int y=st.top().ss;
		st.pop();
		check(x-1,y+1);
		check(x,y);
	}
	return 1;
}
int main(){
    //~ freopen("file.in", "r", stdin);
    scanf("%d%d",&n,&m);
    for(int i=0;i<=n+1;i++)
		for(int j=0;j<=m+1;j++){
			if(!j or !i or i>n or j>m)vis[i][j]=1;
			else dgn[i+j]++;
		}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			int x;
			scanf("%d",&x);
			if(x)assert(mark(i,j));
		}
	int q;
	scanf("%d",&q); 
	while(q--){
		int x,y;
		scanf("%d%d",&x,&y);
		printf("%d\n",mark(x,y));
	}
	return 0;
}

Compilation message

furniture.cpp: In function 'int main()':
furniture.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
furniture.cpp:60:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |    scanf("%d",&x);
      |    ~~~~~^~~~~~~~~
furniture.cpp:64:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |  scanf("%d",&q);
      |  ~~~~~^~~~~~~~~
furniture.cpp:67:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |   scanf("%d%d",&x,&y);
      |   ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 2 ms 716 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 4 ms 716 KB Output is correct
5 Correct 4 ms 716 KB Output is correct
6 Correct 5 ms 716 KB Output is correct
7 Correct 5 ms 716 KB Output is correct
8 Correct 5 ms 716 KB Output is correct
9 Correct 8 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 2 ms 716 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 4 ms 716 KB Output is correct
5 Correct 4 ms 716 KB Output is correct
6 Correct 5 ms 716 KB Output is correct
7 Correct 5 ms 716 KB Output is correct
8 Correct 5 ms 716 KB Output is correct
9 Correct 8 ms 760 KB Output is correct
10 Correct 13 ms 860 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 201 ms 8268 KB Output is correct
13 Correct 96 ms 5820 KB Output is correct
14 Correct 399 ms 13420 KB Output is correct
15 Correct 395 ms 13664 KB Output is correct
16 Correct 401 ms 14692 KB Output is correct
17 Correct 430 ms 15320 KB Output is correct
18 Correct 419 ms 14912 KB Output is correct
19 Correct 477 ms 15756 KB Output is correct
20 Correct 409 ms 15708 KB Output is correct
21 Correct 488 ms 15728 KB Output is correct