結果

問題 No.2731 Two Colors
ユーザー GGanariGGanari
提出日時 2024-04-19 22:00:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 265 ms / 3,000 ms
コード長 2,065 bytes
コンパイル時間 2,268 ms
コンパイル使用メモリ 202,508 KB
実行使用メモリ 11,460 KB
最終ジャッジ日時 2024-04-19 22:00:24
合計ジャッジ時間 6,444 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 244 ms
11,336 KB
testcase_01 AC 245 ms
11,456 KB
testcase_02 AC 265 ms
11,440 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 10 ms
5,376 KB
testcase_05 AC 8 ms
5,376 KB
testcase_06 AC 26 ms
5,376 KB
testcase_07 AC 29 ms
5,376 KB
testcase_08 AC 6 ms
5,376 KB
testcase_09 AC 103 ms
9,660 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 114 ms
11,460 KB
testcase_12 AC 100 ms
9,520 KB
testcase_13 AC 97 ms
9,196 KB
testcase_14 AC 47 ms
6,144 KB
testcase_15 AC 6 ms
5,376 KB
testcase_16 AC 47 ms
5,912 KB
testcase_17 AC 63 ms
6,964 KB
testcase_18 AC 13 ms
5,376 KB
testcase_19 AC 49 ms
6,220 KB
testcase_20 AC 66 ms
7,296 KB
testcase_21 AC 13 ms
5,376 KB
testcase_22 AC 110 ms
10,220 KB
testcase_23 AC 28 ms
5,376 KB
testcase_24 AC 15 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 86 ms
8,528 KB
testcase_27 AC 110 ms
10,424 KB
testcase_28 AC 73 ms
8,148 KB
testcase_29 AC 25 ms
5,376 KB
testcase_30 AC 41 ms
6,220 KB
testcase_31 AC 29 ms
5,376 KB
testcase_32 AC 137 ms
11,456 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define INF 1000000001LL
#define LNF 1000000000000000001LL
#define MOD 998244353LL
#define MAX 1005
#define long long long
#define all(x) x.begin(),x.end()
using namespace std;

int main()
{
	ios_base::sync_with_stdio(0); 
    cin.tie(0);
    int n,m;
    cin >> n >> m;

    int pan[n][m];

    for(int i = 0; i<n; i++)
    {
        for(int j = 0;j<m; j++)
            cin >> pan[i][j];
    }

    int dx[4] = {-1,0,0,1};
    int dy[4] = {0,-1,1,0};
    int vis[n][m];
    memset(vis,0,sizeof vis);

    priority_queue<pair<int,pair<int,int>>> pqA; 
    priority_queue<pair<int,pair<int,int>>> pqB;
    pqA.push({pan[0][0],{0,0}});
    pqB.push({pan[n-1][m-1],{n-1,m-1}});
    int cnt = -2;
    while(true)
    {
        pair<int,int> x = pqA.top().second;
        pqA.pop();
        while(vis[x.first][x.second])
        {
            x = pqA.top().second;
            pqA.pop();
        }
        vis[x.first][x.second] = 1;
        cnt++;
        for(int i = 0; i<4; i++)
        {
            int xx = x.first+dx[i];
            int yy = x.second+dy[i];

            if(xx < 0 || yy < 0 || xx>=n || yy >=m)
                continue;
            if(vis[xx][yy] == 2)
            {
                cout << cnt << endl;
                return 0;
            }
            if(vis[xx][yy])
                continue;
            pqA.push({-pan[xx][yy],{xx,yy}});
        }
        x = pqB.top().second;
        pqB.pop();

        while(vis[x.first][x.second])
        {
            x = pqB.top().second;
            pqB.pop();
        }
        vis[x.first][x.second] = 2;
        cnt++;
        for(int i = 0; i<4; i++)
        {
            int xx = x.first+dx[i];
            int yy = x.second+dy[i];

            if(xx < 0 || yy < 0 || xx>=n || yy >=m)
                continue;
            if(vis[xx][yy] == 1)
            {
                cout << cnt << endl;
                return 0;
            }
            if(vis[xx][yy])
                continue;
            pqB.push({-pan[xx][yy],{xx,yy}});
        }
    }

    return 0;
}
0