結果

問題 No.1605 Matrix Shape
ユーザー aut_jul_duraut_jul_dur
提出日時 2021-07-16 22:30:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,349 bytes
コンパイル時間 4,293 ms
コンパイル使用メモリ 262,300 KB
実行使用メモリ 12,948 KB
最終ジャッジ日時 2023-09-20 14:48:07
合計ジャッジ時間 8,239 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
10,788 KB
testcase_01 AC 7 ms
10,856 KB
testcase_02 AC 5 ms
10,860 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 6 ms
10,668 KB
testcase_06 AC 6 ms
10,668 KB
testcase_07 AC 7 ms
10,808 KB
testcase_08 AC 6 ms
10,860 KB
testcase_09 AC 7 ms
10,928 KB
testcase_10 AC 5 ms
10,724 KB
testcase_11 AC 7 ms
10,924 KB
testcase_12 AC 6 ms
10,808 KB
testcase_13 AC 6 ms
10,792 KB
testcase_14 AC 7 ms
10,888 KB
testcase_15 AC 6 ms
10,736 KB
testcase_16 AC 6 ms
10,748 KB
testcase_17 AC 6 ms
10,788 KB
testcase_18 AC 7 ms
10,920 KB
testcase_19 AC 132 ms
11,060 KB
testcase_20 AC 119 ms
10,880 KB
testcase_21 AC 119 ms
10,924 KB
testcase_22 WA -
testcase_23 AC 132 ms
10,788 KB
testcase_24 AC 131 ms
11,064 KB
testcase_25 AC 81 ms
10,876 KB
testcase_26 AC 80 ms
10,812 KB
testcase_27 AC 81 ms
10,924 KB
testcase_28 AC 79 ms
10,672 KB
testcase_29 AC 79 ms
11,032 KB
testcase_30 AC 116 ms
10,876 KB
testcase_31 AC 116 ms
10,852 KB
testcase_32 AC 107 ms
10,964 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 102 ms
10,832 KB
testcase_36 AC 63 ms
10,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
using mint = modint1000000007;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int main(){
  ll N;
  cin>>N;
  vector<vector<ll>> G(200200);
  vector<ll> aru;
  ll H[200200] = {};
  ll W[200200] = {};
  rep(i,N){
    ll a,b;
    cin>>a>>b;
    if(a == b){
      aru.push_back(a);
      continue;
    }
    H[a]++;
    W[b]++;
  }
  ll d = 0;
  rep(i,aru.size()){
    if(H[aru[i]] == 0 && W[aru[i]] == 0){
      d = 1;
    }
  }
  ll Hh = 0;
  ll Wh = 0;
  rep(i,200200){
    if(abs(H[i]-W[i]) > 1){
      d = 1;
    }
    else if(H[i]-W[i] == 1){
      Hh++;
    }
    else if(W[i]-H[i] == 1){
      Wh++;
    }
    else{
      continue;
    }
  }
  if(d){
    cout << 0 << endl;
    return 0;
  }
  if(Hh == 0 && Wh == 0){
    ll ans = 0;
    rep(i,200200){
      if(H[i]>0){
        ans++;
      }
    }
    cout << ans << endl;
  }
  else if(Hh == 1 && Wh == 1){
    cout << 1 << endl;
  }
  else{
    cout << 0 << endl;
  }
  return 0;
}
0