結果
| 問題 | No.3029 オイラー標数 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-02-21 22:19:47 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 208 ms / 2,000 ms |
| コード長 | 2,033 bytes |
| 記録 | |
| コンパイル時間 | 1,073 ms |
| コンパイル使用メモリ | 182,296 KB |
| 実行使用メモリ | 33,632 KB |
| 最終ジャッジ日時 | 2026-07-05 00:17:47 |
| 合計ジャッジ時間 | 5,075 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include <iostream>
#include <unordered_set>
#include <tuple>
using namespace std;
// 自定义pair哈希
struct PairHash {
size_t operator()(const pair<int, int>& p) const {
return hash<long long>()( ((long long)p.first << 32) | p.second );
}
};
// 自定义tuple哈希
struct TupleHash {
size_t operator()(const tuple<int, int, int>& t) const {
auto hash1 = hash<int>{}(get<0>(t));
auto hash2 = hash<int>{}(get<1>(t));
auto hash3 = hash<int>{}(get<2>(t));
return (hash1 ^ (hash2 << 1)) ^ (hash3 << 2);
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int Q;
cin >> Q;
unordered_set<int> vertices;
unordered_set<pair<int, int>, PairHash> edges;
unordered_set<tuple<int, int, int>, TupleHash> faces;
int v_count = 0, e_count = 0, f_count = 0;
while (Q--) {
int a, b, c;
cin >> a >> b >> c;
// 顶点处理(同之前)
int new_v = 0;
if (!vertices.count(a)) { vertices.insert(a); new_v++; }
if (!vertices.count(b)) { vertices.insert(b); new_v++; }
if (!vertices.count(c)) { vertices.insert(c); new_v++; }
v_count += new_v;
// 边处理(必须标准化)
auto e1 = make_pair(min(a, b), max(a, b));
auto e2 = make_pair(min(b, c), max(b, c));
auto e3 = make_pair(min(c, a), max(c, a));
int new_e = 0;
if (!edges.count(e1)) { edges.insert(e1); new_e++; }
if (!edges.count(e2)) { edges.insert(e2); new_e++; }
if (!edges.count(e3)) { edges.insert(e3); new_e++; }
e_count += new_e;
// 面处理(全排序)
int x = min({a, b, c});
int z = max({a, b, c});
int y = a + b + c - x - z;
auto f = make_tuple(x, y, z);
if (!faces.count(f)) {
faces.insert(f);
f_count++;
}
}
cout << v_count - e_count + f_count << endl;
return 0;
}