結果
| 問題 |
No.2251 Marking Grid
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-03-18 15:03:07 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 318 ms / 3,000 ms |
| コード長 | 1,505 bytes |
| コンパイル時間 | 798 ms |
| コンパイル使用メモリ | 92,356 KB |
| 最終ジャッジ日時 | 2025-02-11 15:05:14 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 40 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:42:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
42 | scanf("%d %d", &h, &w);
| ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:48:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
48 | scanf("%d", &v);
| ~~~~~^~~~~~~~~~
ソースコード
#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;
}