結果
問題 |
No.1479 Matrix Eraser
|
ユーザー |
![]() |
提出日時 | 2021-04-16 20:52:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,883 bytes |
コンパイル時間 | 2,010 ms |
コンパイル使用メモリ | 184,532 KB |
実行使用メモリ | 26,248 KB |
最終ジャッジ日時 | 2024-07-02 23:35:04 |
合計ジャッジ時間 | 13,408 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 WA * 3 TLE * 1 -- * 13 |
コンパイルメッセージ
main.cpp: In function 'int f(std::vector<std::pair<long long int, long long int> >)': main.cpp:48:37: warning: 'yy' may be used uninitialized [-Wmaybe-uninitialized] 48 | if(p[i].second==yy) | ^~ main.cpp:25:33: note: 'yy' was declared here 25 | int maxx=0, xx, maxy=0, yy; | ^~ main.cpp:42:36: warning: 'xx' may be used uninitialized [-Wmaybe-uninitialized] 42 | if(p[i].first==xx) | ^~ main.cpp:25:21: note: 'xx' was declared here 25 | int maxx=0, xx, maxy=0, yy; | ^~
ソースコード
#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; }