QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#601488#7733. Cool, It’s Yesterday Four Times Morekans2298TL 1ms5724kbC++203.7kb2024-09-30 01:35:282024-09-30 01:35:29

Judging History

你现在查看的是最新测评结果

  • [2024-09-30 01:35:29]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:5724kb
  • [2024-09-30 01:35:28]
  • 提交

answer

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <utility>
#include<set>
using namespace std;
const int way[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};
short a[1001][1001];
short b[1001][1001];
vector<pair<short,short>> all_block[1001];
set<pair<short,short>> c[1001];
vector<pair<short, short>> new_block;
queue<pair<short, short>> q;
int main()
{
     int t, ti;
     //freopen("input.in","r",stdin);
     ios::sync_with_stdio(false);
     cin.tie(nullptr);
     cin >> t;
     for (ti = 1; ti <= t; ++ti)
     {
          int n, m, i, j, cnt1 = 0;
          cin >> n >> m;
          for (int i=0;i<=n;++i)
               for (int j=0;j<=m;++j)
                    a[i][j]=b[i][j]=0;
          for (int i=0;i<=n*m;++i)
               {
               all_block[i].clear();
               c[i].clear();
               }
          for (i = 1; i <= n; ++i)
          {
               string s;
               cin >> s;
               for (j = 0; j < m; ++j)
                    if (s[j] == '.')
                         a[i][j + 1] = 1; // 1 means empty area
                    else
                         a[i][j + 1] = 0; // 0 means unexisted way
          }
          for (i = 1; i <= n; ++i)
               for (j = 1; j <= m; ++j)
                    if (a[i][j] == 1 && b[i][j] == 0)
                    {
                         auto bfs = [&]()
                         {
                              new_block.clear();
                              q.push({i, j});
                              b[i][j] = cnt1;
                              new_block.push_back({i, j});
                              while (q.empty() == false)
                              {
                                   const auto [x, y] = q.front();
                                   q.pop();
                                   for (int k = 0; k < 4; ++k)
                                   {
                                        const int nx = x + way[k][0], ny = y + way[k][1];
                                        if (not (nx>=1 && nx<=n && ny>=1 && ny<=m)) continue;
                                        if (a[nx][ny] == 1 && b[nx][ny] == 0)
                                        {
                                             q.push({nx, ny});
                                             b[nx][ny] = cnt1;
                                             new_block.push_back({nx, ny});
                                        }
                                   }
                              }
                              all_block[cnt1]=new_block;
                         };
                         bfs();
                         ++cnt1;
                    }
          int cnt2=0;
          for (i=1;i<=n;++i)
               for (j=1;j<=m;++j)
                    if (a[i][j]==1)
                         {
                         int idx=b[i][j];
                         set<pair<short,short>> s;
                         for (auto [x,y]:all_block[idx])
                              s.insert({x-i,y-j});
                         c[cnt2++]=s;
                         }
          int ans=0;
          for (i=0;i<cnt2;++i)
               {
               int oppo=cnt2-1;
               for (j=0;j<cnt2;++j)
                    {
                    if (i==j) continue;
                    for (const auto point:c[i])
                         if (c[j].count(point)==0)
                              {
                              oppo-=1;
                              break;
                              }
                    }
               if (oppo==0) ++ans;
               }
          cout<<ans<<"\n";
     }
     return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5724kb

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
Time Limit Exceeded

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:


result: