답안 #488630

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
488630 2021-11-19T19:19:38 Z cfalas Furniture (JOI20_furniture) C++14
5 / 100
5000 ms 1112 KB
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;

#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)

int t, n, m;

vector<vi> a, b, c;

void calc(){
	b[0][0] = 1;
	FORi(i,1,n) b[i][0] = min(b[i-1][0], (int)(a[i][0]==0));
	FORi(i,1,m) b[0][i] = min(b[0][i-1], (int)(a[0][i]==0));

	c[n-1][m-1] = 1;
	for(int i=n-2;i>=0;i--) c[i][m-1] = min(c[i+1][m-1], (int)(a[i][m-1]==0));
	for(int i=m-2;i>=0;i--) c[n-1][i] = min(c[n-1][i+1], (int)(a[n-1][i]==0));
	FORi(i,1,n){
		FORi(j,1,m){
			if(a[i][j]) b[i][j] = 0;
			else b[i][j] = b[i-1][j] + b[i][j-1];
		}
	}
	for(int i=n-2;i>=0;i--){
		for(int j=m-2;j>=0;j--){
			if(a[i][j]) c[i][j] = 0;
			else c[i][j] = c[i+1][j] + c[i][j+1];
		}
	}
	/** FOR(i,n){
		FOR(j,m) cout<<c[i][j]<<" ";
		cout<<endl;
	}*/
	//assert(b[n-1][m-1]!=0);
}

int main(){
	cin>>n>>m;
	b.assign(n, vi(m));
	c.assign(n, vi(m));
	a.assign(n, vi(m));
	FOR(i,n){
		FOR(j,m) cin>>a[i][j];
	}

	int q;
	cin>>q;

	calc();
	/*
	FOR(i,n){
		FOR(j,m) cout<<b[i][j]<<" ";
		cout<<endl;
	}*/

	while(q--){
		int x,y;
		cin>>x>>y;
		//cout<<b[n-1][m-1]<<" "<<b[x-1][y-1]<<" "<<c[x-1][y-1]<<endl;
		if(b[n-1][m-1]!=c[x-1][y-1]*b[x-1][y-1]){
			cout<<1<<endl, a[x-1][y-1] = 1;
			calc();
		}
		else cout<<0<<endl;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 332 KB Output is correct
2 Correct 59 ms 340 KB Output is correct
3 Correct 157 ms 376 KB Output is correct
4 Correct 338 ms 408 KB Output is correct
5 Correct 377 ms 464 KB Output is correct
6 Correct 465 ms 416 KB Output is correct
7 Correct 284 ms 452 KB Output is correct
8 Correct 334 ms 420 KB Output is correct
9 Correct 230 ms 400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 332 KB Output is correct
2 Correct 59 ms 340 KB Output is correct
3 Correct 157 ms 376 KB Output is correct
4 Correct 338 ms 408 KB Output is correct
5 Correct 377 ms 464 KB Output is correct
6 Correct 465 ms 416 KB Output is correct
7 Correct 284 ms 452 KB Output is correct
8 Correct 334 ms 420 KB Output is correct
9 Correct 230 ms 400 KB Output is correct
10 Execution timed out 5057 ms 1112 KB Time limit exceeded
11 Halted 0 ms 0 KB -