QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#328380 | #833. Cells Blocking | Call_me_Eric | WA | 1ms | 4272kb | C++17 | 2.3kb | 2024-02-15 19:48:20 | 2024-02-15 19:48:21 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
bool stmemory;
namespace Call_me_Eric{
inline int read(){
int x = 0, f = 1;char ch = getchar();
while(ch < '0' || ch > '9'){if(ch == '-') f = -1;ch = getchar();}
while(ch >= '0' && ch <= '9'){x = (x << 1) + (x << 3) + (ch ^ 48);ch = getchar();}
return x * f;
}
const int maxn = 3e3 + 10;
int n, m;
char ch[maxn][maxn];
bool f[maxn][maxn], g[maxn][maxn];
vector<int> vec[maxn * 3];
void main(){
int cnt = 0;
n = read(); m = read();
for(int i = 1;i <= n;i++){
scanf("%s",ch[i] + 1);
for(int j = 1;j <= m;j++)
cnt += ch[i][j] == '.';
}
f[1][1] = g[n][m] = 1;ch[1][1] = ch[n][m] = '.';
for(int i = 1;i <= n;i++)for(int j = 1;j <= m;j++)
if(i + j != 2 && ch[i][j] == '.')
f[i][j] = f[i][j - 1] | f[i - 1][j];
for(int i = n;i;i--)for(int j = m;j;j--)
if(i + j != n + m && ch[i][j] == '.')
g[i][j] = g[i][j + 1] | g[i + 1][j];
if(!g[1][1]){printf("%lld\n",cnt * (cnt - 1) / 2);return;}
for(int i = 1;i <= n;i++){
for(int j = 1;j <= m;j++){
if(!f[i][j] || !g[i][j])ch[i][j] = '*';
else{vec[i + j].push_back(i);}
}
}
int ans = 0;
for(int i = 2;i <= n + m;i++)if(vec[i].size() == 1){cnt--;ans += cnt;}
for(int i = 2;i <= n + m;i++){
if(vec[i].size() > 1){
ans += vec[i].size() == 2;
int l = vec[i][1], r = vec[i].back();
for(int j = i + 1;j <= n + m;j++){
if(ch[l][j - l] != '.')l++;
if(ch[r + 1][j - r - 1] == '.')r++;
if(l == r && vec[j].size() != 1)ans++;
}
l = vec[i].front(), r = vec[i][vec[i].size() - 2];
for(int j = i + 1;j <= n + m;j++){
if(ch[l][j - l] != '.')l++;
if(ch[r + 1][j - r - 1] == '.')r++;
if(l == r && vec[j].size() != 1)ans++;
}
}
}
printf("%lld\n",ans);
return;
}
};
bool edmemory;
signed main(){
auto stclock = clock();
Call_me_Eric::main();
auto edclock = clock();
cerr << (&stmemory - &edmemory) / 1024.0 / 1024.0 << " Mib cost.\n";
cerr << (edclock - stclock) * 1.0 / CLOCKS_PER_SEC << " Sec cost.\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4224kb
input:
3 3 ... ... ...
output:
17
result:
ok 1 number(s): "17"
Test #2:
score: 0
Accepted
time: 1ms
memory: 4272kb
input:
3 3 .** .*. ...
output:
15
result:
ok 1 number(s): "15"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 4228kb
input:
3 4 **** .... ****
output:
3
result:
wrong answer 1st numbers differ - expected: '6', found: '3'