# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
831220 |
2023-08-19T23:45:31 Z |
NK_ |
Towers (NOI22_towers) |
C++17 |
|
1450 ms |
133816 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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 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 |
0 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 |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
10440 KB |
Output is correct |
2 |
Correct |
42 ms |
12152 KB |
Output is correct |
3 |
Correct |
116 ms |
34592 KB |
Output is correct |
4 |
Correct |
242 ms |
67484 KB |
Output is correct |
5 |
Correct |
35 ms |
13044 KB |
Output is correct |
6 |
Correct |
7 ms |
2924 KB |
Output is correct |
7 |
Correct |
259 ms |
63904 KB |
Output is correct |
8 |
Correct |
158 ms |
44852 KB |
Output is correct |
9 |
Correct |
412 ms |
99252 KB |
Output is correct |
10 |
Correct |
346 ms |
84200 KB |
Output is correct |
11 |
Correct |
402 ms |
103732 KB |
Output is correct |
12 |
Correct |
439 ms |
103560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
902 ms |
107372 KB |
Output is correct |
2 |
Correct |
903 ms |
107460 KB |
Output is correct |
3 |
Correct |
913 ms |
107476 KB |
Output is correct |
4 |
Correct |
922 ms |
107472 KB |
Output is correct |
5 |
Correct |
899 ms |
107492 KB |
Output is correct |
6 |
Correct |
1418 ms |
133808 KB |
Output is correct |
7 |
Correct |
1402 ms |
133796 KB |
Output is correct |
8 |
Correct |
1450 ms |
133764 KB |
Output is correct |
9 |
Correct |
1422 ms |
133744 KB |
Output is correct |
10 |
Correct |
1412 ms |
133816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 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 |
0 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 |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
0 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 |
3 ms |
852 KB |
Output is correct |
29 |
Correct |
3 ms |
852 KB |
Output is correct |
30 |
Correct |
3 ms |
852 KB |
Output is correct |
31 |
Correct |
3 ms |
852 KB |
Output is correct |
32 |
Correct |
3 ms |
852 KB |
Output is correct |
33 |
Correct |
3 ms |
860 KB |
Output is correct |
34 |
Correct |
3 ms |
852 KB |
Output is correct |
35 |
Correct |
3 ms |
852 KB |
Output is correct |
36 |
Correct |
2 ms |
852 KB |
Output is correct |
37 |
Correct |
2 ms |
752 KB |
Output is correct |
38 |
Correct |
2 ms |
852 KB |
Output is correct |
39 |
Correct |
2 ms |
852 KB |
Output is correct |
40 |
Correct |
2 ms |
852 KB |
Output is correct |
41 |
Correct |
2 ms |
852 KB |
Output is correct |
42 |
Correct |
2 ms |
852 KB |
Output is correct |
43 |
Correct |
2 ms |
852 KB |
Output is correct |
44 |
Correct |
2 ms |
724 KB |
Output is correct |
45 |
Correct |
2 ms |
724 KB |
Output is correct |
46 |
Correct |
2 ms |
744 KB |
Output is correct |
47 |
Correct |
2 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 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 |
0 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 |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
0 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 |
3 ms |
852 KB |
Output is correct |
29 |
Correct |
3 ms |
852 KB |
Output is correct |
30 |
Correct |
3 ms |
852 KB |
Output is correct |
31 |
Correct |
3 ms |
852 KB |
Output is correct |
32 |
Correct |
3 ms |
852 KB |
Output is correct |
33 |
Correct |
3 ms |
860 KB |
Output is correct |
34 |
Correct |
3 ms |
852 KB |
Output is correct |
35 |
Correct |
3 ms |
852 KB |
Output is correct |
36 |
Correct |
2 ms |
852 KB |
Output is correct |
37 |
Correct |
2 ms |
752 KB |
Output is correct |
38 |
Correct |
2 ms |
852 KB |
Output is correct |
39 |
Correct |
2 ms |
852 KB |
Output is correct |
40 |
Correct |
2 ms |
852 KB |
Output is correct |
41 |
Correct |
2 ms |
852 KB |
Output is correct |
42 |
Correct |
2 ms |
852 KB |
Output is correct |
43 |
Correct |
2 ms |
852 KB |
Output is correct |
44 |
Correct |
2 ms |
724 KB |
Output is correct |
45 |
Correct |
2 ms |
724 KB |
Output is correct |
46 |
Correct |
2 ms |
744 KB |
Output is correct |
47 |
Correct |
2 ms |
852 KB |
Output is correct |
48 |
Correct |
67 ms |
15156 KB |
Output is correct |
49 |
Correct |
64 ms |
15172 KB |
Output is correct |
50 |
Correct |
75 ms |
14004 KB |
Output is correct |
51 |
Correct |
77 ms |
14004 KB |
Output is correct |
52 |
Correct |
59 ms |
11488 KB |
Output is correct |
53 |
Correct |
60 ms |
11576 KB |
Output is correct |
54 |
Correct |
61 ms |
11616 KB |
Output is correct |
55 |
Correct |
53 ms |
11296 KB |
Output is correct |
56 |
Correct |
58 ms |
11256 KB |
Output is correct |
57 |
Correct |
55 ms |
11248 KB |
Output is correct |
58 |
Correct |
49 ms |
11184 KB |
Output is correct |
59 |
Correct |
50 ms |
11288 KB |
Output is correct |
60 |
Correct |
45 ms |
11180 KB |
Output is correct |
61 |
Correct |
45 ms |
11280 KB |
Output is correct |
62 |
Correct |
44 ms |
11212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 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 |
0 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 |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
31 ms |
10440 KB |
Output is correct |
27 |
Correct |
42 ms |
12152 KB |
Output is correct |
28 |
Correct |
116 ms |
34592 KB |
Output is correct |
29 |
Correct |
242 ms |
67484 KB |
Output is correct |
30 |
Correct |
35 ms |
13044 KB |
Output is correct |
31 |
Correct |
7 ms |
2924 KB |
Output is correct |
32 |
Correct |
259 ms |
63904 KB |
Output is correct |
33 |
Correct |
158 ms |
44852 KB |
Output is correct |
34 |
Correct |
412 ms |
99252 KB |
Output is correct |
35 |
Correct |
346 ms |
84200 KB |
Output is correct |
36 |
Correct |
402 ms |
103732 KB |
Output is correct |
37 |
Correct |
439 ms |
103560 KB |
Output is correct |
38 |
Correct |
902 ms |
107372 KB |
Output is correct |
39 |
Correct |
903 ms |
107460 KB |
Output is correct |
40 |
Correct |
913 ms |
107476 KB |
Output is correct |
41 |
Correct |
922 ms |
107472 KB |
Output is correct |
42 |
Correct |
899 ms |
107492 KB |
Output is correct |
43 |
Correct |
1418 ms |
133808 KB |
Output is correct |
44 |
Correct |
1402 ms |
133796 KB |
Output is correct |
45 |
Correct |
1450 ms |
133764 KB |
Output is correct |
46 |
Correct |
1422 ms |
133744 KB |
Output is correct |
47 |
Correct |
1412 ms |
133816 KB |
Output is correct |
48 |
Correct |
3 ms |
980 KB |
Output is correct |
49 |
Correct |
3 ms |
980 KB |
Output is correct |
50 |
Correct |
3 ms |
852 KB |
Output is correct |
51 |
Correct |
3 ms |
852 KB |
Output is correct |
52 |
Correct |
3 ms |
852 KB |
Output is correct |
53 |
Correct |
3 ms |
852 KB |
Output is correct |
54 |
Correct |
3 ms |
852 KB |
Output is correct |
55 |
Correct |
3 ms |
860 KB |
Output is correct |
56 |
Correct |
3 ms |
852 KB |
Output is correct |
57 |
Correct |
3 ms |
852 KB |
Output is correct |
58 |
Correct |
2 ms |
852 KB |
Output is correct |
59 |
Correct |
2 ms |
752 KB |
Output is correct |
60 |
Correct |
2 ms |
852 KB |
Output is correct |
61 |
Correct |
2 ms |
852 KB |
Output is correct |
62 |
Correct |
2 ms |
852 KB |
Output is correct |
63 |
Correct |
2 ms |
852 KB |
Output is correct |
64 |
Correct |
2 ms |
852 KB |
Output is correct |
65 |
Correct |
2 ms |
852 KB |
Output is correct |
66 |
Correct |
2 ms |
724 KB |
Output is correct |
67 |
Correct |
2 ms |
724 KB |
Output is correct |
68 |
Correct |
2 ms |
744 KB |
Output is correct |
69 |
Correct |
2 ms |
852 KB |
Output is correct |
70 |
Correct |
67 ms |
15156 KB |
Output is correct |
71 |
Correct |
64 ms |
15172 KB |
Output is correct |
72 |
Correct |
75 ms |
14004 KB |
Output is correct |
73 |
Correct |
77 ms |
14004 KB |
Output is correct |
74 |
Correct |
59 ms |
11488 KB |
Output is correct |
75 |
Correct |
60 ms |
11576 KB |
Output is correct |
76 |
Correct |
61 ms |
11616 KB |
Output is correct |
77 |
Correct |
53 ms |
11296 KB |
Output is correct |
78 |
Correct |
58 ms |
11256 KB |
Output is correct |
79 |
Correct |
55 ms |
11248 KB |
Output is correct |
80 |
Correct |
49 ms |
11184 KB |
Output is correct |
81 |
Correct |
50 ms |
11288 KB |
Output is correct |
82 |
Correct |
45 ms |
11180 KB |
Output is correct |
83 |
Correct |
45 ms |
11280 KB |
Output is correct |
84 |
Correct |
44 ms |
11212 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 |
1343 ms |
133216 KB |
Output is correct |
89 |
Correct |
1441 ms |
133240 KB |
Output is correct |
90 |
Correct |
1375 ms |
133288 KB |
Output is correct |
91 |
Correct |
1138 ms |
110208 KB |
Output is correct |
92 |
Correct |
1129 ms |
110292 KB |
Output is correct |
93 |
Correct |
1194 ms |
110236 KB |
Output is correct |
94 |
Correct |
1082 ms |
107788 KB |
Output is correct |
95 |
Correct |
1016 ms |
107844 KB |
Output is correct |
96 |
Correct |
1044 ms |
107864 KB |
Output is correct |
97 |
Correct |
920 ms |
108016 KB |
Output is correct |
98 |
Correct |
940 ms |
108044 KB |
Output is correct |
99 |
Correct |
930 ms |
108104 KB |
Output is correct |
100 |
Correct |
881 ms |
105876 KB |
Output is correct |
101 |
Correct |
834 ms |
105884 KB |
Output is correct |
102 |
Correct |
831 ms |
105540 KB |
Output is correct |
103 |
Correct |
938 ms |
105548 KB |
Output is correct |
104 |
Correct |
862 ms |
105744 KB |
Output is correct |
105 |
Correct |
842 ms |
105616 KB |
Output is correct |
106 |
Correct |
838 ms |
104112 KB |
Output is correct |
107 |
Correct |
795 ms |
104124 KB |
Output is correct |