結果

問題 No.1479 Matrix Eraser
ユーザー HaaHaa
提出日時 2021-04-16 20:52:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,883 bytes
コンパイル時間 1,977 ms
コンパイル使用メモリ 183,028 KB
実行使用メモリ 26,076 KB
最終ジャッジ日時 2023-09-15 22:14:24
合計ジャッジ時間 13,738 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
15,556 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 35 ms
6,308 KB
testcase_08 AC 66 ms
8,332 KB
testcase_09 AC 163 ms
14,076 KB
testcase_10 AC 369 ms
22,504 KB
testcase_11 AC 204 ms
15,784 KB
testcase_12 AC 46 ms
6,952 KB
testcase_13 AC 66 ms
8,444 KB
testcase_14 AC 47 ms
7,388 KB
testcase_15 AC 11 ms
4,380 KB
testcase_16 AC 54 ms
7,900 KB
testcase_17 AC 485 ms
26,016 KB
testcase_18 AC 509 ms
25,936 KB
testcase_19 AC 500 ms
25,944 KB
testcase_20 AC 503 ms
26,076 KB
testcase_21 AC 496 ms
25,940 KB
testcase_22 AC 496 ms
25,892 KB
testcase_23 AC 499 ms
26,064 KB
testcase_24 AC 499 ms
25,956 KB
testcase_25 AC 494 ms
26,064 KB
testcase_26 AC 498 ms
25,948 KB
testcase_27 TLE -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int f(std::vector<std::pair<long long int, long long int> >)’ 内:
main.cpp:48:37: 警告: ‘yy’ may be used uninitialized [-Wmaybe-uninitialized]
   48 |                     if(p[i].second==yy)
      |                                     ^~
main.cpp:25:33: 備考: ‘yy’ はここで定義されています
   25 |         int maxx=0, xx, maxy=0, yy;
      |                                 ^~
main.cpp:42:36: 警告: ‘xx’ may be used uninitialized [-Wmaybe-uninitialized]
   42 |                     if(p[i].first==xx)
      |                                    ^~
main.cpp:25:21: 備考: ‘xx’ はここで定義されています
   25 |         int maxx=0, xx, maxy=0, yy;
      |                     ^~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=998244353;
constexpr ll INF=2e18;

int f(vector<P> p){
    int n=p.size();
    VI used(n,0);
    int ret=0;
    while(1){
        ret++;
        map<int,int> x, y;
        REP(i,n){
            if(!used[i]){
                x[p[i].first]++;
                y[p[i].second]++;
            }
        }
        int maxx=0, xx, maxy=0, yy;
        for(auto q:x){
            if(maxx<q.second){
                maxx=q.second;
                xx=q.first;
            }
        }
        for(auto q:y){
            if(maxy<q.second){
                maxy=q.second;
                yy=q.first;
            }
        }
        bool bre=1;
        REP(i,n){
            if(!used[i]){
                if(maxx>maxy){
                    if(p[i].first==xx)
                        used[i]=1;
                    else
                        bre=0;
                }
                else{
                    if(p[i].second==yy)
                        used[i]=1;
                    else
                        bre=0;
                }
            }
        }
        if(bre)
            break;
    }
    return ret;
}

int main(){
    int h, w; cin >> h >> w;
    VVI a(h,VI(w));
    REP(i,h)REP(j,w) cin >> a[i][j];
    map<int,int> mp; int k=1;
    REP(i,h)REP(j,w){
        if(a[i][j]==0)
            continue;
        if(mp[a[i][j]]==0){
            mp[a[i][j]]=k;
            k++;
        }
    }
    vector<vector<P>> p(k);
    REP(i,h)REP(j,w){
        if(a[i][j]==0)
            continue;
        int id=mp[a[i][j]]-1;
        p[id].push_back({i,j});
    }
    int ans=0;
    REP(i,k-1){
        ans+=f(p[i]);
    }
    cout << ans << endl;
    return 0;
}
0