結果

問題 No.2251 Marking Grid
ユーザー lddlinanlddlinan
提出日時 2023-03-18 15:03:07
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 352 ms / 3,000 ms
コード長 1,505 bytes
コンパイル時間 776 ms
コンパイル使用メモリ 91,444 KB
実行使用メモリ 15,684 KB
最終ジャッジ日時 2023-10-18 17:18:10
合計ジャッジ時間 5,323 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 288 ms
15,684 KB
testcase_23 AC 349 ms
15,684 KB
testcase_24 AC 10 ms
4,348 KB
testcase_25 AC 352 ms
15,684 KB
testcase_26 AC 60 ms
6,980 KB
testcase_27 AC 166 ms
15,684 KB
testcase_28 AC 7 ms
4,348 KB
testcase_29 AC 180 ms
15,684 KB
testcase_30 AC 50 ms
6,972 KB
testcase_31 AC 32 ms
4,544 KB
testcase_32 AC 14 ms
4,348 KB
testcase_33 AC 224 ms
15,684 KB
testcase_34 AC 20 ms
4,544 KB
testcase_35 AC 98 ms
10,528 KB
testcase_36 AC 132 ms
10,528 KB
testcase_37 AC 182 ms
15,684 KB
testcase_38 AC 8 ms
4,348 KB
testcase_39 AC 6 ms
4,348 KB
testcase_40 AC 88 ms
10,528 KB
testcase_41 AC 41 ms
6,980 KB
権限があれば一括ダウンロードができます

ソースコード

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
int bb[2048];
int gg[2048], gx[2048];
int sk[2048];
int findg(int g) {
    int st=0;
    while(g!=gg[g]) {
        sk[st++]=g; g=gg[g];
    }
    while(st) gg[sk[--st]]=g;
    return g;
}
int main() {
    int n, i, x, j, h, w, c, p, v, k;
    LL r, b, t;
    RNode xt;
    scanf("%d %d", &h, &w);
    for (i=0; i<h+w; i++) { gg[i]=i; gx[i]=0; }
    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});
        }
    }
    bb[0]=1; for (i=1; i<=x; i++) bb[i]=(bb[i-1]*2)%MOD;
    r=0;  c=h+w;
    while(!q.empty()) {
        xt = q.top();
        i=findg(xt.i); j=findg(xt.j+h);
        if (i!=j) {
            if (gx[i]==gx[j]) gx[i]++;
            if (gx[i]>gx[j]) gg[j]=i;
            else gg[i]=j;
            c--;
            t=bb[c-1]; t*=xt.h; t%=MOD;
            r+=t; r%=MOD;
        }
        q.pop();
    }
    printf("%lld\n", r);
    return 0;
}
0