답안 #771406

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
771406 2023-07-02T23:54:36 Z NK_ Port Facility (JOI17_port_facility) C++17
0 / 100
1 ms 212 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'
#define f first
#define s second
#define mp make_pair

using ll = long long;
using pi = pair<int, int>;
template<class T> using V = vector<T>;
using vi = V<int>;

struct DSU {
	vi e; void init(int N) { e = vi(N, -1); }
	int get(int x) { return e[x] < 0 ? x : e[x] = get(e[x]); }
	bool unite(int x, int y) {
		x = get(x), y = get(y); if (x == y) return 0;
		if (e[x] > e[y]) swap(x, y);
		e[x] += e[y]; e[y] = x; return 1;
	}
};

int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N; cin >> N;

	V<pi> E(2*N);

	vi A(N), B(N); for(int i = 0; i < N; i++) {
		cin >> A[i] >> B[i]; --A[i], --B[i];
		E[A[i]] = mp(i, +1);
		E[B[i]] = mp(i, -1);
	}

	DSU D; D.init(N); 
	set<pi> R; int P = N;
	for(int t = 0; t < 2 * N; t++) {
		int i = E[t].f;
		// cout << t << " -> " << i << endl;
		if (E[t].s == +1) {
			for(auto r : R) {
				if (r.f > B[i]) break;
				if (!D.unite(i, r.s)) {
					cout << 0 << nl;
					exit(0);
				} else P--;
			}

			R.insert(mp(B[i], i));
		}

		if (E[t].s == -1) {
			R.erase(mp(B[i], i));
		}
	}


	const int MOD = 1e9 + 7;
	ll ANS = 1, x = 2;

	for(; P; P /= 2, x = (x * x) % MOD) if (P & 1) ANS = (ANS * x) % MOD;

	cout << ANS << nl;







    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -