답안 #831221

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
831221 2023-08-19T23:46:06 Z NK_ Towers (NOI22_towers) C++17
100 / 100
1507 ms 118428 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;
 
#define nl '\n'
#define pb push_back
#define pf push_front

#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
 
template<class T> using V = vector<T>;
using pi = pair<int, int>;
using vi = V<int>;
using vpi = V<pi>;

using ll = long long;
using pl = pair<ll, ll>;
using vpl = V<pl>;
using vl = V<ll>;

using db = long double;

template<class T> using pq = priority_queue<T, V<T>, greater<T>>;

const int MOD = 1e9 + 7;
const ll INFL = ll(1e16) + 10;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N; cin >> N;
	vpi A(N); for(auto& x : A) {
		cin >> x.f >> x.s;
	}

	int ROWS = 0, COLS = 0;
	for(int t = 0; t < 2; t++) {
		vi X; for(auto& x : A) X.pb(x.f); 

		sort(begin(X), end(X)); 
		X.erase(unique(begin(X), end(X)), end(X));

		for(auto& x : A) {
			x.f = lower_bound(begin(X), end(X), x.f) - begin(X);
			swap(x.f, x.s);
		}

		ROWS = sz(X); swap(ROWS, COLS);
	}

	unordered_map<ll, int> IDX; for(int i = 0; i < N; i++) {
		IDX[A[i].f * 1LL * COLS + A[i].s] = i;
	}

	V<vi> C(COLS);
	for(int i = 0; i < N; i++) C[A[i].s].pb(A[i].f);
	for(int i = 0; i < COLS; i++) sort(begin(C[i]), end(C[i]));

	const pi EMP = mp(-1, -1);
	vpi RF(ROWS, EMP); 
	vpi RB(ROWS, EMP); 


	vi POS(2 * COLS, -1); int Q = 0;
	vi stk;
	function<void(int)> update = [&](int X) {
		stk.pb(X);

		while(sz(stk)) {

			int x = stk.back(); stk.pop_back(); 
			if (POS[x] == -1) continue;

			// 2*y+c => y is col # and c is dir (0 - dwn (+1), 1 - up (-1));
			int y = x / 2, dir = (x % 2 ? -1 : +1);
			while(1) {
				Q++; assert(Q <= 5 * N);

				if (POS[x] < 0 || POS[x] >= sz(C[y])) {
					POS[x] = -1; break;
				}

				if (POS[2*y] == POS[2*y+1]) {
					POS[x] = -1;
					break; // stop because same as other one
				}

				int r = C[y][POS[x]]; // row

				// check if you can put it in
				if (RB[r] == EMP || RB[r].f < y) { // sz(R[r]) == 2 put in at the back
					if (RB[r] != EMP) {
						int i = RB[r].s;
						RB[r] = mp(y, x);
						stk.pb(i); 
					} else RB[r] = mp(y, x);
					break;
				} 

				if (RF[r] == EMP || y < RF[r].f) { // sz(R[r]) == 2 put in at the front
					if (RF[r] != EMP) {
						int i = RF[r].s;
						RF[r] = mp(y, x);
						stk.pb(i);
					} else RF[r] = mp(y, x);
					break;
				}

				POS[x] += dir;
			}
		}
	};


	for(int c = 0; c < COLS; c++) {
		POS[2 * c] = 0; 
		update(2 * c); 

		POS[2 * c + 1] = sz(C[c]) - 1;
		update(2 * c + 1);
	}

	vpi take;
	for(int i = 0; i < 2 * COLS; i++) {
		int c = i / 2; 
		if (0 <= POS[i] && POS[i] < sz(C[c])) {
			take.pb(mp(C[c][POS[i]], c));
		}
	}

	string ans(N, '0');
	for(auto& p : take) {
		ans[IDX[p.f * 1LL * COLS + p.s]] = '1';
	}

	cout << ans << nl;

	// cerr << Q << endl;


    return 0;
} 	
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 6112 KB Output is correct
2 Correct 27 ms 6932 KB Output is correct
3 Correct 76 ms 18736 KB Output is correct
4 Correct 160 ms 36064 KB Output is correct
5 Correct 27 ms 7300 KB Output is correct
6 Correct 8 ms 1772 KB Output is correct
7 Correct 168 ms 34456 KB Output is correct
8 Correct 97 ms 25216 KB Output is correct
9 Correct 272 ms 55404 KB Output is correct
10 Correct 308 ms 47188 KB Output is correct
11 Correct 256 ms 56928 KB Output is correct
12 Correct 255 ms 56804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 841 ms 73604 KB Output is correct
2 Correct 858 ms 73616 KB Output is correct
3 Correct 864 ms 73640 KB Output is correct
4 Correct 841 ms 73616 KB Output is correct
5 Correct 833 ms 73572 KB Output is correct
6 Correct 1505 ms 118304 KB Output is correct
7 Correct 1507 ms 118276 KB Output is correct
8 Correct 1492 ms 118360 KB Output is correct
9 Correct 1384 ms 118364 KB Output is correct
10 Correct 1418 ms 118428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 3 ms 980 KB Output is correct
27 Correct 3 ms 980 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 2 ms 596 KB Output is correct
30 Correct 3 ms 596 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 2 ms 596 KB Output is correct
33 Correct 2 ms 596 KB Output is correct
34 Correct 2 ms 596 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 2 ms 596 KB Output is correct
37 Correct 2 ms 524 KB Output is correct
38 Correct 2 ms 596 KB Output is correct
39 Correct 2 ms 596 KB Output is correct
40 Correct 2 ms 596 KB Output is correct
41 Correct 2 ms 596 KB Output is correct
42 Correct 2 ms 596 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 2 ms 596 KB Output is correct
45 Correct 2 ms 596 KB Output is correct
46 Correct 2 ms 596 KB Output is correct
47 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 3 ms 980 KB Output is correct
27 Correct 3 ms 980 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 2 ms 596 KB Output is correct
30 Correct 3 ms 596 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 2 ms 596 KB Output is correct
33 Correct 2 ms 596 KB Output is correct
34 Correct 2 ms 596 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 2 ms 596 KB Output is correct
37 Correct 2 ms 524 KB Output is correct
38 Correct 2 ms 596 KB Output is correct
39 Correct 2 ms 596 KB Output is correct
40 Correct 2 ms 596 KB Output is correct
41 Correct 2 ms 596 KB Output is correct
42 Correct 2 ms 596 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 2 ms 596 KB Output is correct
45 Correct 2 ms 596 KB Output is correct
46 Correct 2 ms 596 KB Output is correct
47 Correct 2 ms 596 KB Output is correct
48 Correct 69 ms 14904 KB Output is correct
49 Correct 64 ms 14832 KB Output is correct
50 Correct 70 ms 12192 KB Output is correct
51 Correct 70 ms 12200 KB Output is correct
52 Correct 50 ms 7332 KB Output is correct
53 Correct 50 ms 7348 KB Output is correct
54 Correct 51 ms 7324 KB Output is correct
55 Correct 43 ms 6688 KB Output is correct
56 Correct 43 ms 6688 KB Output is correct
57 Correct 43 ms 6668 KB Output is correct
58 Correct 37 ms 6584 KB Output is correct
59 Correct 41 ms 6556 KB Output is correct
60 Correct 32 ms 6464 KB Output is correct
61 Correct 31 ms 6588 KB Output is correct
62 Correct 32 ms 6508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 24 ms 6112 KB Output is correct
27 Correct 27 ms 6932 KB Output is correct
28 Correct 76 ms 18736 KB Output is correct
29 Correct 160 ms 36064 KB Output is correct
30 Correct 27 ms 7300 KB Output is correct
31 Correct 8 ms 1772 KB Output is correct
32 Correct 168 ms 34456 KB Output is correct
33 Correct 97 ms 25216 KB Output is correct
34 Correct 272 ms 55404 KB Output is correct
35 Correct 308 ms 47188 KB Output is correct
36 Correct 256 ms 56928 KB Output is correct
37 Correct 255 ms 56804 KB Output is correct
38 Correct 841 ms 73604 KB Output is correct
39 Correct 858 ms 73616 KB Output is correct
40 Correct 864 ms 73640 KB Output is correct
41 Correct 841 ms 73616 KB Output is correct
42 Correct 833 ms 73572 KB Output is correct
43 Correct 1505 ms 118304 KB Output is correct
44 Correct 1507 ms 118276 KB Output is correct
45 Correct 1492 ms 118360 KB Output is correct
46 Correct 1384 ms 118364 KB Output is correct
47 Correct 1418 ms 118428 KB Output is correct
48 Correct 3 ms 980 KB Output is correct
49 Correct 3 ms 980 KB Output is correct
50 Correct 2 ms 596 KB Output is correct
51 Correct 2 ms 596 KB Output is correct
52 Correct 3 ms 596 KB Output is correct
53 Correct 3 ms 596 KB Output is correct
54 Correct 2 ms 596 KB Output is correct
55 Correct 2 ms 596 KB Output is correct
56 Correct 2 ms 596 KB Output is correct
57 Correct 2 ms 596 KB Output is correct
58 Correct 2 ms 596 KB Output is correct
59 Correct 2 ms 524 KB Output is correct
60 Correct 2 ms 596 KB Output is correct
61 Correct 2 ms 596 KB Output is correct
62 Correct 2 ms 596 KB Output is correct
63 Correct 2 ms 596 KB Output is correct
64 Correct 2 ms 596 KB Output is correct
65 Correct 2 ms 596 KB Output is correct
66 Correct 2 ms 596 KB Output is correct
67 Correct 2 ms 596 KB Output is correct
68 Correct 2 ms 596 KB Output is correct
69 Correct 2 ms 596 KB Output is correct
70 Correct 69 ms 14904 KB Output is correct
71 Correct 64 ms 14832 KB Output is correct
72 Correct 70 ms 12192 KB Output is correct
73 Correct 70 ms 12200 KB Output is correct
74 Correct 50 ms 7332 KB Output is correct
75 Correct 50 ms 7348 KB Output is correct
76 Correct 51 ms 7324 KB Output is correct
77 Correct 43 ms 6688 KB Output is correct
78 Correct 43 ms 6688 KB Output is correct
79 Correct 43 ms 6668 KB Output is correct
80 Correct 37 ms 6584 KB Output is correct
81 Correct 41 ms 6556 KB Output is correct
82 Correct 32 ms 6464 KB Output is correct
83 Correct 31 ms 6588 KB Output is correct
84 Correct 32 ms 6508 KB Output is correct
85 Correct 0 ms 212 KB Output is correct
86 Correct 0 ms 212 KB Output is correct
87 Correct 0 ms 212 KB Output is correct
88 Correct 1271 ms 115936 KB Output is correct
89 Correct 1346 ms 116048 KB Output is correct
90 Correct 1337 ms 115936 KB Output is correct
91 Correct 854 ms 67984 KB Output is correct
92 Correct 810 ms 67992 KB Output is correct
93 Correct 821 ms 67996 KB Output is correct
94 Correct 747 ms 63296 KB Output is correct
95 Correct 737 ms 63188 KB Output is correct
96 Correct 736 ms 63164 KB Output is correct
97 Correct 745 ms 62544 KB Output is correct
98 Correct 747 ms 62612 KB Output is correct
99 Correct 741 ms 62440 KB Output is correct
100 Correct 630 ms 59352 KB Output is correct
101 Correct 625 ms 59304 KB Output is correct
102 Correct 580 ms 58724 KB Output is correct
103 Correct 586 ms 58704 KB Output is correct
104 Correct 501 ms 58764 KB Output is correct
105 Correct 540 ms 58824 KB Output is correct
106 Correct 373 ms 57244 KB Output is correct
107 Correct 390 ms 57168 KB Output is correct