QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#549353#7733. Cool, It’s Yesterday Four Times MoreFoedere0RE 0ms0kbC++142.4kb2024-09-06 14:42:242024-09-06 14:42:24

Judging History

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

  • [2024-09-06 14:42:24]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-09-06 14:42:24]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef pair<int, int> PII;
int n, m;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int s[1010][1010];
vector<PII> p;
vector<PII> q;
struct node
{
    int x, y, o, p;
};
//map<vector<int>, int> mp;
queue<node> heap;
bool check(int x, int y)
{
    if (x >= 1 && x <= n && y >= 1 && y <= m && s[x][y] == 1)
        return true;
    return false;
}
void solve()
{
    //mp.clear();
    p.clear();
    q.clear();
    cin >> n >> m;
    bool mp[n][m][n][m] = {0};
    for (int i = 0; i <= n + 1; i++)
    {
        for (int j = 0; j <= m + 1; j++)
        {
            char ch;
            if (i == 0 || i == n + 1 || j == 0 || j == m + 1)
            {
                ch = 'O';
            }
            else
                cin >> ch;
            if (ch == 'O')
            {
                s[i][j] = 0;
                q.push_back({i, j});
            }
            else
            {
                p.push_back({i, j});
                s[i][j] = 1;
            }
        }
    }

    for (auto x : p)
    {
        for (auto y : q)
        {
            node t;
            t.x = x.first, t.y = x.second, t.o = y.first, t.p = y.second;
            mp[t.x][t.y][t.o][t.p] = 1;
            heap.push(t);
        }
    }
    while (heap.size())
    {
        node t = heap.front();
        heap.pop();
        for (int i = 0; i < 4; i++)
        {
            int xx = dx[i] + t.x, yy = dy[i] + t.y;
            int oo = dx[i] + t.o, pp = dy[i] + t.p;
            if (check(xx, yy) && check(oo, pp) && !mp[xx][yy][oo][pp])
            {
                mp[xx][yy][oo][pp] = 1;
                heap.push({xx, yy, oo, pp});
            }
        }
    }
    int sum = 0;
    for (auto x : p)
    {
        bool noans = 0;
        for (auto y : p)
        {
            if (x.first == y.first && x.second == y.second)
            {
                continue;
            }
            if (!mp[x.first][x.second][y.first][y.second])
            {
                noans = 1;
                break;
            }
        }
        if (!noans)
        {
            sum++;
        }
    }
    cout << sum << endl;
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

4
2 5
.OO..
O..O.
1 3
O.O
1 3
.O.
2 3
OOO
OOO

output:


result: