結果

問題 No.1479 Matrix Eraser
ユーザー rgkb0303rgkb0303
提出日時 2021-04-16 22:05:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,160 bytes
コンパイル時間 2,869 ms
コンパイル使用メモリ 169,572 KB
実行使用メモリ 43,056 KB
最終ジャッジ日時 2023-09-16 00:46:51
合計ジャッジ時間 6,752 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
26,436 KB
testcase_01 AC 15 ms
26,508 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 34 ms
28,248 KB
testcase_08 AC 52 ms
29,608 KB
testcase_09 AC 94 ms
32,924 KB
testcase_10 AC 161 ms
37,688 KB
testcase_11 AC 104 ms
34,096 KB
testcase_12 AC 40 ms
28,772 KB
testcase_13 AC 53 ms
29,744 KB
testcase_14 AC 42 ms
28,932 KB
testcase_15 AC 19 ms
26,868 KB
testcase_16 AC 46 ms
29,296 KB
testcase_17 AC 200 ms
39,608 KB
testcase_18 AC 197 ms
39,636 KB
testcase_19 AC 198 ms
39,532 KB
testcase_20 AC 200 ms
39,792 KB
testcase_21 AC 197 ms
39,652 KB
testcase_22 AC 199 ms
39,628 KB
testcase_23 AC 192 ms
39,756 KB
testcase_24 AC 195 ms
39,768 KB
testcase_25 AC 205 ms
39,644 KB
testcase_26 AC 204 ms
39,608 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 53 ms
29,732 KB
testcase_33 AC 53 ms
29,980 KB
testcase_34 AC 53 ms
29,824 KB
testcase_35 AC 54 ms
29,664 KB
testcase_36 AC 54 ms
29,968 KB
testcase_37 AC 55 ms
29,996 KB
testcase_38 AC 66 ms
29,672 KB
testcase_39 AC 149 ms
43,056 KB
testcase_40 AC 15 ms
26,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  
  vector<vector<int>> vv(h, vector<int>(w));
  vector<vector<int>> vi(500001, vector<int>(0));
  vector<vector<int>> vj(500001, vector<int>(0));
  
  
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int x;
      cin >> x;
      vv.at(i).at(j) = x;
      vi.at(x).push_back(i + 1);
    }
  }
  
  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      int y = vv.at(j).at(i);
      vj.at(y).push_back(i + 1);
    }
  }
  
  
  int count = 0;
  
  for (int i = 1; i < vi.size(); i++) {
    int vs = vi.at(i).size();
    
    if (vs == 0) {      
      continue;
    }
    
    else if (vs == 1) {
      count++;
    }
    
    else {
      int icount = 0;
      int jcount = 0;
      int pre_m = 0;
      int pre_n = 0;
      
      for (int m : vi.at(i)) {
        if (m != pre_m) {
          icount++;
          pre_m = m;
        }
      }
      for (int n : vj.at(i)) {
        if (n != pre_n) {
          jcount++;
          pre_n = n;
        }
      }
      count += min(icount, jcount);
    }
  }
  cout << count << endl;
}
0