結果

問題 No.2251 Marking Grid
ユーザー lddlinanlddlinan
提出日時 2023-03-18 03:26:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,504 bytes
コンパイル時間 834 ms
コンパイル使用メモリ 91,380 KB
実行使用メモリ 19,268 KB
最終ジャッジ日時 2023-10-18 17:03:02
合計ジャッジ時間 3,698 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;

bool rcmp(int a, int b) { return a>b; }
typedef long long LL;
typedef struct { int h, i, j; } RNode;
class mypcmp {
public:
    bool operator()(const RNode& a, const RNode& b) {
        return a.h<b.h;
    }
};
#define MOD 998244353
char mk[1024][1024];
short quei[1024*1024];
short quej[1024*1024];
char ss[][2] = {{-1, -1}, {0, 0}, {-1, 0}, {0, -1}};
void clearit(int i, int j, int hh, int w) {
    int h, t, ni, nj, k, c;
    // printf("clear %d,%d\n", i, j);
    h=t=0;
    mk[i][j]=1;
    quei[h]=i; quej[h]=j; h++;
    while(t<h) {
        i=quei[t]; j=quej[t]; t++;
        // printf("process %d,%d\n", i, j);
        // 4 block
        for (k=0; k<4; k++) {
            ni=i+ss[k][0];
            nj=j+ss[k][1];
            if (ni<0||nj<0||ni>=hh-1||nj>=w-1) continue;
            c=mk[ni][nj]+mk[ni+1][nj+1]+mk[ni+1][nj]+mk[ni][nj+1];
            if (c==3) {
                if (mk[ni+1][nj+1]==0) {
                    mk[ni+1][nj+1]=1;
                    quei[h]=ni+1; quej[h]=nj+1; h++;
                } else if (mk[ni+1][nj]==0) {
                    mk[ni+1][nj]=1;
                    quei[h]=ni+1; quej[h]=nj; h++;
                } else if (mk[ni][nj]==0) {
                    mk[ni][nj]=1;
                    quei[h]=ni; quej[h]=nj; h++;
                } else {
                    mk[ni][nj+1]=1;
                    quei[h]=ni; quej[h]=nj+1; h++;
                }
            }
        }
    }
}
int bb[2048];
int main() {
    int n, i, x, j, h, w, c, p, v, k;
    LL r, b, t;
    RNode xt;
    scanf("%d %d", &h, &w);
    x = h+w-1; c=0;
    priority_queue<RNode, vector<RNode>, mypcmp> q;
    for (i=0; i<h; i++) {
        for (j=0; j<w; j++) {
            scanf("%d", &v);
            q.push({v, i, j});
            mk[i][j]=0;
        }
    }
    bb[0]=1; for (i=1; i<=x; i++) bb[i]=(bb[i-1]*2)%MOD;
    r=0; 
    while(x) { x--;
        while(!q.empty()) {
            xt = q.top();
            i=xt.i; j=xt.j;
            if (mk[i][j]==0) break;
            q.pop();
        }
        if (q.empty()) break;
        xt = q.top(); q.pop();
        p=xt.h;
        clearit(xt.i, xt.j, h, w);
        t=bb[x]; t*=p; t%=MOD;
        r+=t; r%=MOD;
    }
    printf("%lld\n", r);
    return 0;
}
0