样例过了,但是0分
查看原帖
样例过了,但是0分
934390
__HappY__楼主2024/5/24 20:30
#include<bits/stdc++.h>
#define int long long
using namespace std;
int r, c;
const int N = 1e4 + 911;
char a[N][N];
int ans = 0;
void dfs(int x, int y) {
	if(x < 1 || x > r || y < 1 || y > c) return ;
	if(a[x][y] != '*') {
		if(a[x][y] == 'S') ans += 1;
		if(a[x][y] == 'M') ans += 5;
		if(a[x][y] == 'L') ans += 10;
		a[x][y] = '*';
		dfs(x + 1, y);
		dfs(x - 1, y);
		dfs(x, y + 1);
		dfs(x, y - 1);
	}
}

signed main() {
	cin >> r >> c;
	for(int i = 1; i <= r; i++)
		for(int j = 1; j <= c; j++) 
			cin >> a[i][j];
	int i, j;
	cin >> i >>j;
	dfs(i, j);
	cout << ans;
	return 0;
}
2024/5/24 20:30
加载中...