結果

問題 No.2731 Two Colors
ユーザー snrnsidysnrnsidy
提出日時 2024-04-19 23:18:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,347 bytes
コンパイル時間 2,566 ms
コンパイル使用メモリ 200,320 KB
実行使用メモリ 316,796 KB
最終ジャッジ日時 2024-04-19 23:18:19
合計ジャッジ時間 11,967 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int n,m;
int A[1001][1001];
int board[1001][1001];

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

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

    priority_queue <pair<int,pair<int,int>>> pque[2];
    memset(board,-1,sizeof(board));
    pque[0].push(make_pair(-A[0][0],make_pair(0,0)));
    pque[1].push(make_pair(-A[n-1][m-1],make_pair(n-1,m-1)));

    int res = 0;
    while(1)
    {
        int y = pque[res%2].top().second.first;
        int x = pque[res%2].top().second.second;
        pque[res%2].pop();

        //cout << res+1 << ' ' << res%2 << ' ' << y << ' ' << x << '\n';
        board[y][x] = res%2;

        bool ok = true;
        for(int i=0;i<4;i++)
        {
            int ny = y + dy[i];
            int nx = x + dx[i];
            if(ny < 0 || ny >= n || nx < 0 || nx >= m) continue;
            if(board[ny][nx] == (1 - res%2))
            {
                ok = false;
            }
            else if(board[ny][nx] == -1)
            {
                pque[res%2].push(make_pair(-A[ny][nx],make_pair(ny,nx)));
            }
        }
        if(!ok) break;
        res+=1;
    }
    cout << res-1 << '\n';   
	return 0;
}
0