結果

問題 No.2251 Marking Grid
ユーザー lddlinan
提出日時 2023-03-18 03:26:19
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,504 bytes
コンパイル時間 1,187 ms
コンパイル使用メモリ 91,376 KB
最終ジャッジ日時 2025-02-11 14:50:39
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 12 WA * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:69:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   69 |     scanf("%d %d", &h, &w);
      |     ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:74:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   74 |             scanf("%d", &v);
      |             ~~~~~^~~~~~~~~~

ソースコード

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