結果

問題 No.1479 Matrix Eraser
ユーザー monnumonnu
提出日時 2021-04-16 21:06:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,113 bytes
コンパイル時間 1,711 ms
コンパイル使用メモリ 175,844 KB
実行使用メモリ 6,244 KB
最終ジャッジ日時 2023-09-15 22:46:38
合計ジャッジ時間 12,730 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,500 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 34 ms
4,380 KB
testcase_08 AC 64 ms
4,380 KB
testcase_09 AC 172 ms
4,380 KB
testcase_10 AC 422 ms
5,360 KB
testcase_11 AC 223 ms
4,600 KB
testcase_12 AC 56 ms
4,380 KB
testcase_13 AC 64 ms
4,376 KB
testcase_14 AC 57 ms
4,376 KB
testcase_15 AC 9 ms
4,376 KB
testcase_16 AC 53 ms
4,380 KB
testcase_17 AC 560 ms
5,984 KB
testcase_18 AC 560 ms
6,060 KB
testcase_19 AC 564 ms
5,932 KB
testcase_20 AC 560 ms
5,932 KB
testcase_21 AC 562 ms
5,940 KB
testcase_22 AC 567 ms
5,932 KB
testcase_23 AC 561 ms
5,912 KB
testcase_24 AC 562 ms
5,996 KB
testcase_25 AC 563 ms
5,988 KB
testcase_26 AC 561 ms
6,072 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 48 ms
5,996 KB
testcase_38 AC 529 ms
5,936 KB
testcase_39 AC 542 ms
5,908 KB
testcase_40 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 200003
#define MOD 998244353
#define INF 1000000000

int main(){
  int H,W;
  cin>>H>>W;
  vector<vector<int>> A(H,vector<int>(W));
  vector<pair<int,int>> a(H*W);
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>A[i][j];
      a[i*W+j]=make_pair(A[i][j],i*W+j);
    }
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());

  int ans=0;
  for(int cnt=0;cnt<H*W;cnt++){
    int x=a[cnt].first;
    int i=a[cnt].second/W;
    int j=a[cnt].second%W;
    if(A[i][j]==0){
      continue;
    }
    ans++;
    int cnt1=0;
    int cnt2=0;
    for(int k=0;k<H;k++){
      if(A[k][j]==x){
        cnt1++;
      }
    }
    for(int k=0;k<W;k++){
      if(A[i][k]==x){
        cnt2++;
      }
    }
    if(cnt1>cnt2){
      for(int k=0;k<H;k++){
        if(A[k][j]==x){
          A[k][j]=0;
        }
      }
    }else{
      for(int k=0;k<W;k++){
        if(A[i][k]==x){
          A[i][k]=0;
        }
      }
    }
  }
  cout<<ans<<endl;
}
0