22012023-01-02 13:57:53kohumarkJegesmedve (50)cpp11Wrong answer 16/50377ms3784 KiB
#include <bits/stdc++.h>
#define speed ios::sync_with_stdio(0);cin.tie(0)
using namespace std;


int main(){
	speed;
	int n, m, x, y;
	cin >> n >> m;
	int t[n][m]; int f[n][m]; int c[n][m];
	for(int i=0; i<n; i++) for(int j=0; j<m; j++){
		cin >> t[i][j];
		c[i][j] = 0;
		if(t[i][j]==-1){x=i; y=j;}
	}
	for(int i=0; i<n; i++) for(int j=0; j<m; j++) cin >> f[i][j];
	long long int temp=0;
	int e=0;
	int old=0; int r=0;
	while(true){
		for(int k=0; k<2; k++){
			for(int i=0; i<n+m; i++){
				for(int j=-i; j<i+1; j++){
					int dx1=x+i-abs(j);
					int dx2=x-i+abs(j);
					int dy=y+j;
					if((dx1>-1&&dx1<n&&dy>-1&&dy<m)&&(t[dx1][dy]==-1 || t[dx1][dy] >= temp)&&((t[dx1][dy]==-1)||(dx1-1>-1&&c[dx1-1][dy])||(dx1+1<n&&c[dx1+1][dy])||(dy-1>-1&&c[dx1][dy-1])||(dy+1<m&&c[dx1][dy+1]))) c[dx1][dy]=1;
					if((dx2>-1&&dx2<n&&dy>-1&&dy<m)&&(t[dx2][dy]==-1 || t[dx2][dy] >= temp)&&((t[dx2][dy]==-1)||(dx2-1>-1&&c[dx2-1][dy])||(dx2+1<n&&c[dx2+1][dy])||(dy-1>-1&&c[dx2][dy-1])||(dy+1<m&&c[dx2][dy+1]))) c[dx2][dy]=1;
				}
			}
		}
		if(old==e) r++;
		else r=0;
		if(r==e){temp--; break;}
		old=e; e=0;
		for(int i=0; i<n; i++) for(int j=0; j<m; j++) if(c[i][j]){
			e+=f[i][j];
			c[i][j]=0;
		}
		if(old==e&&temp>0&&e-1==1) break;
		if(e==0) break;
		temp++;
	}
	cout << temp;
}
SubtaskSumTestVerdictTimeMemory
base16/50
1Accepted0/03ms1896 KiB
2Accepted0/0177ms2084 KiB
3Wrong answer0/37ms2304 KiB
4Wrong answer0/313ms2656 KiB
5Accepted3/34ms2876 KiB
6Wrong answer0/416ms3140 KiB
7Accepted3/327ms3016 KiB
8Accepted3/345ms3144 KiB
9Accepted3/365ms3372 KiB
10Accepted4/486ms3420 KiB
11Time limit exceeded0/4356ms2744 KiB
12Time limit exceeded0/4377ms3708 KiB
13Time limit exceeded0/4365ms3784 KiB
14Time limit exceeded0/4361ms3248 KiB
15Time limit exceeded0/4349ms3392 KiB
16Time limit exceeded0/4349ms3464 KiB