QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#704698 | #7733. Cool, It’s Yesterday Four Times More | cbbdhz | WA | 1ms | 5800kb | C++20 | 2.6kb | 2024-11-02 20:39:30 | 2024-11-02 20:39:32 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 5001;
char tu[N][N];
int vis[N][N];
int movee[] = { -1,0,1,0,-1 };
int cnt = 1;
vector<vector<array<int, 2>>>dxdy(N);
int n, m;
void dfs(int x, int y)
{
queue<array<int, 2>>que;
que.push({ x,y });
while (!que.empty())
{
auto [tx, ty] = que.front();
dxdy[cnt].push_back({ tx - x,ty - y });
que.pop();
vis[tx][ty] = cnt;
for (int i = 0; i < 4; i++)
{
int nx = tx + movee[i]; int ny = ty + movee[i + 1];
if (nx <= 0 || nx > n || ny <= 0 || ny > m || vis[nx][ny] || tu[nx][ny] == 'O')continue;
que.push({ nx,ny });
}
}
}
void init(int n, int m)
{
for (int i = 1; i <= n * m; i++)
{
dxdy[i].clear();
}
for (int i = 1; i <= n; i++)for (int j = 1; j <= m; j++)
{
vis[i][j] = 0;
}
cnt = 1;
}
void solve()
{
cin >> n >> m;
init(n, m);
for (int i = 1; i <= n; i++)for (int j = 1; j <= m; j++)
{
cin >> tu[i][j];
}
for (int i = 1; i <= n; i++)for (int j = 1; j <= m; j++)
{
if (!vis[i][j] && tu[i][j] == '.')
{
dfs(i, j);
cnt++;
}
}
/*for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
cout << vis[i][j] << "";
}
cout << endl;
}*/
int ans = 0;
for (int k = 1; k < cnt; k++)
{
int flag = 1;
for (int i = 1; i <= n; i++)
{
if (!flag)break;
int j;
for (j = 1; j <= m; j++)
{
if (vis[i][j] == k||tu[i][j]=='O')continue;
int l;
for (l=0;l<dxdy[k].size();l++)
{
int dx = dxdy[k][l][0]; int dy = dxdy[k][l][1];
int nx = i + dx; int ny = j + dy;
if (nx <= 0 || nx > n || ny <= 0 || ny > m || tu[nx][ny] == 'O')
{
break;
}
}
if (l == dxdy[k].size()) {
flag = false;
}
}
}
if (flag)ans += dxdy[k].size();
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T; cin >> T;
while (T--)
{
solve();
}
}
/*
4
2 5
.OO..
O..O.
1 3
O.O
1 3
.O.
2 3
OOO
OOO
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5720kb
input:
4 2 5 .OO.. O..O. 1 3 O.O 1 3 .O. 2 3 OOO OOO
output:
3 1 0 0
result:
ok 4 lines
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 5800kb
input:
200 2 4 OOO. OO.. 2 3 OOO .O. 3 3 O.O OOO OO. 4 1 . . O O 1 2 .O 1 1 . 2 5 .OO.. .O.O. 2 1 O O 1 1 O 1 3 .OO 5 1 O O . O . 5 2 O. .. O. .O .. 5 3 ... ... .OO ..O OOO 3 5 ..O.O .O.O. .OO.O 5 2 .O OO O. O. .. 2 1 O O 3 5 .O.OO O...O ..OO. 1 5 ..... 5 1 O . O . . 5 3 OOO OO. .OO OO. O.O 2 1 O . 5 2 O. ...
output:
3 0 0 2 1 1 3 0 0 1 0 7 12 4 4 0 6 5 2 0 1 6 4 6 2 0 0 7 3 3 1 4 1 0 7 5 2 3 7 3 0 9 2 2 2 0 4 6 6 3 3 2 3 5 2 1 0 3 3 4 4 2 2 0 7 6 4 12 5 3 2 5 2 1 2 1 4 0 0 2 5 1 4 9 7 1 6 2 2 3 4 5 2 1 0 1 17 3 4 19 0 3 2 1 0 0 4 3 1 4 3 11 3 0 3 6 2 5 1 3 3 4 0 2 16 2 2 4 0 4 4 6 2 1 2 3 0 5 0 27 4 3 2 6 0 8 3...
result:
wrong answer 13th lines differ - expected: '9', found: '12'