結果
| 問題 |
No.1605 Matrix Shape
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2021-07-16 21:41:05 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,567 bytes |
| コンパイル時間 | 1,258 ms |
| コンパイル使用メモリ | 119,284 KB |
| 最終ジャッジ日時 | 2025-01-23 01:33:20 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 RE * 1 |
| other | AC * 17 WA * 1 RE * 16 |
ソースコード
#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;
}
}
milanis48663220