結果

問題 No.1605 Matrix Shape
ユーザー milanis48663220milanis48663220
提出日時 2021-07-16 21:41:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,567 bytes
コンパイル時間 1,143 ms
コンパイル使用メモリ 123,356 KB
実行使用メモリ 15,644 KB
最終ジャッジ日時 2023-09-20 13:24:33
合計ジャッジ時間 4,851 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,564 KB
testcase_01 RE -
testcase_02 AC 4 ms
4,692 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 4 ms
4,488 KB
testcase_08 RE -
testcase_09 AC 3 ms
4,576 KB
testcase_10 AC 3 ms
4,620 KB
testcase_11 AC 3 ms
4,548 KB
testcase_12 RE -
testcase_13 AC 4 ms
4,512 KB
testcase_14 AC 3 ms
4,560 KB
testcase_15 AC 3 ms
4,584 KB
testcase_16 AC 3 ms
4,580 KB
testcase_17 AC 3 ms
4,576 KB
testcase_18 AC 3 ms
4,620 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 38 ms
6,208 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 AC 45 ms
6,152 KB
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 31 ms
6,168 KB
testcase_28 RE -
testcase_29 AC 31 ms
6,092 KB
testcase_30 RE -
testcase_31 AC 39 ms
6,348 KB
testcase_32 RE -
testcase_33 WA -
testcase_34 RE -
testcase_35 AC 36 ms
6,084 KB
testcase_36 AC 21 ms
5,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> n;
    vector<int> in(200000), out(200000);
    vector<int> h(n), w(n);
    for(int i = 0; i < n; i++){
        cin >> h[i] >> w[i]; h[i]--; w[i]--;
        out[w[i]]++;
        in[h[i]]++;
    }
    int cnt_s = 0;
    int cnt_t = 0;
    for(int i = 0; i < 200000; i++){
        if(abs(in[i]-out[i]) > 1){
            cout << 0 << endl;
            return 0;
        }
        if(in[i] > out[i]) cnt_t++;
        if(out[i] > in[i]) cnt_s++;
    }
    if(cnt_t ==  cnt_s){
        if(cnt_t == 0) {
            set<P> st;
            for(int i = 0; i < n; i++) st.insert(P(h[i], w[i]));
            cout << st.size() << endl;
            return -1;
        }
        else if(cnt_t == 1) cout << 1 << endl;
        else cout << 0 << endl;
    }else{
        cout << 0 << endl;
    }
}
0