답안 #855567

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
855567 2023-10-01T12:43:02 Z jmyszka2007 Crossing (JOI21_crossing) C++17
49 / 100
7000 ms 148964 KB
#include <bits/stdc++.h>
#include <fstream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template<class A, class B>
ostream& operator<<(ostream& o, const pair<A, B>& p) {return o << '(' << p.first << ", " << p.second << ')';}
template<size_t Index = 0, typename... Types>
ostream& printTupleElements(ostream& o, const tuple<Types...>& t) {if constexpr (Index < sizeof...(Types)){if(Index > 0){o << ", ";}o << get<Index>(t);printTupleElements<Index + 1>(o, t);}return o;}
template<typename... Types>
ostream& operator<<(ostream& o, const tuple<Types...>& t){o << "(";printTupleElements(o, t);return o << ")";}
template<class T>
auto operator<<(ostream& o, const T& x) -> decltype(x.end(), o){o << '{';bool first = true;for (const auto& e : x){if (!first){o << ", ";}o << e;first = false;} return o << '}';}
//#define DEBUG
#ifdef DEBUG
#define fastio()
#define debug(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n'
#define check(x) if (!(x)) { cerr << "Check failed: " << #x << " in line " << __LINE__ << endl; exit(1); }
#else
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0);
#define debug(...)
#define check(x) 
#endif
typedef long long ll;
#define pi pair<int, int>
#define pll pair<ll, ll>
#define st first
#define nd second
#define vi vector<int>
#define vll vector<ll>
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
void wypisz(string a) {
	for(auto x : a) {
		cout << x;
	}
	cout << '\n';
}
vector<char>lit = {'J', 'O', 'I'};
string comb(string a, string b) {
	string res = "";
	for(int i = 0; i < sz(a); i++) {
		if(a[i] == b[i]) {
			res += a[i];
		}
		else {
			for(auto x : lit) {
				if(x != a[i] && x != b[i]) {
					res += x;
				}
			}
		}
	}
	return res;
}
set<tuple<int, int, char> > getprz(string a) {
	set<tuple<int, int, char> >res;
	for(int i = 0; i < sz(a); i++) {
		int r = i;
		while(r + 1 < sz(a) && a[r + 1] == a[i]) {
			r++;
		}
		res.insert(make_tuple(i, r, a[i]));
		i = r;
	}
	return res;
}
void solve() {
	//ifstream cin("nazwa.in");
	//ofstream cout("nazwa.out");
	int n;
	cin >> n;
	string a, b, c;
	cin >> a >> b >> c;
	set<string>kt1;
	for(int mask = 1; mask < (1 << 3); mask++) {
		vector<string>per;
		if(mask & (1 << 0)) {
			per.eb(a);
		}
		if(mask & (1 << 1)) {	
			per.eb(b);
		}
		if(mask & (1 << 2)) {
			per.eb(c);
		}
		sort(all(per));
		do {
			string akt = per[0];
			for(int i = 1; i < sz(per); i++) {
				akt = comb(akt, per[i]);
			}
			kt1.insert(akt);
		}while(next_permutation(all(per)));
	}
	vector<string>kt;
	for(auto x : kt1) {
		kt.eb(x);
	}
	vector<set<tuple<int, int, char> > >prz(sz(kt));
	vector<set<tuple<int, int, char> > >przroz(sz(kt));
	for(int i = 0; i < sz(kt); i++) {
		prz[i] = getprz(kt[i]);
		//debug(prz[i]);
	}
	int t;
	cin >> t;
	string s;
	cin >> s;
	set<tuple<int, int, char> >przs = getprz(s);
	for(int i = 0; i < sz(kt); i++) {
		for(auto [l, r, z] : przs) {
			auto it = prz[i].upper_bound(make_tuple(l, 1e9, 1e9));
			it--;
			auto [lp, rp, zn] = *it;
			if(zn != z || rp < r) {
				przroz[i].insert(make_tuple(l, r, z));
			}
		}
	}
	while(t >= 0) {
		bool czy = 0;
		debug(przs);
		for(int i = 0; i < sz(kt); i++) {
			debug(prz[i], przroz[i]);
			if(!sz(przroz[i])) {
				czy = 1;
			}
		}
		if(czy) {
			cout << "Yes\n";
		}
		else {
			cout << "No\n";
		}
		if(t > 0) {
			int l, r;
			char zn;
			cin >> l >> r >> zn;
			l--, r--;
			auto it = przs.upper_bound(make_tuple(l, 1e9, 1e9));
			it--;
			set<tuple<int, int, char> >dod;
			set<tuple<int, int, char> >us;
			while(it != przs.end()) {
				auto [lp, rp, z] = (*it);
				if(lp > r) {
					break;
				}
				if(lp < l) {
					dod.insert(make_tuple(lp, l - 1, z));
				}
				if(rp > r) {
					dod.insert(make_tuple(r + 1, rp, z));
				}
				us.insert(*it);
				for(int i = 0; i < sz(kt); i++) {
					if(przroz[i].find(*it) != przroz[i].end()) {
						przroz[i].erase(*it);
					}
				}
				it++;
			}
			dod.insert(make_tuple(l, r, zn));
			for(auto x : us) {
				przs.erase(x);
			}
			for(auto x : dod) {
				przs.insert(x);
				auto [l, r, z] = x;
				for(int i = 0; i < sz(kt); i++) {
					auto it = prz[i].upper_bound(make_tuple(l, 1e9, 1e9));
					it--;
					auto [lp, rp, z2] = *it;
					if(z2 != z || rp < r) {
						przroz[i].insert(x);
					}
				}
			}
		}
		t--;
	}
}
int main() {
	fastio();
	int t = 1;
	//cin >> t;
	while(t--) {
		solve();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 852 KB Output is correct
2 Correct 251 ms 944 KB Output is correct
3 Correct 171 ms 1004 KB Output is correct
4 Correct 191 ms 884 KB Output is correct
5 Correct 192 ms 2228 KB Output is correct
6 Correct 195 ms 1872 KB Output is correct
7 Correct 195 ms 1876 KB Output is correct
8 Correct 202 ms 1924 KB Output is correct
9 Correct 209 ms 1876 KB Output is correct
10 Correct 214 ms 1872 KB Output is correct
11 Correct 219 ms 1876 KB Output is correct
12 Correct 214 ms 2024 KB Output is correct
13 Correct 220 ms 1876 KB Output is correct
14 Correct 211 ms 2024 KB Output is correct
15 Correct 223 ms 2072 KB Output is correct
16 Correct 220 ms 2236 KB Output is correct
17 Correct 223 ms 1936 KB Output is correct
18 Correct 129 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 852 KB Output is correct
2 Correct 251 ms 944 KB Output is correct
3 Correct 171 ms 1004 KB Output is correct
4 Correct 191 ms 884 KB Output is correct
5 Correct 192 ms 2228 KB Output is correct
6 Correct 195 ms 1872 KB Output is correct
7 Correct 195 ms 1876 KB Output is correct
8 Correct 202 ms 1924 KB Output is correct
9 Correct 209 ms 1876 KB Output is correct
10 Correct 214 ms 1872 KB Output is correct
11 Correct 219 ms 1876 KB Output is correct
12 Correct 214 ms 2024 KB Output is correct
13 Correct 220 ms 1876 KB Output is correct
14 Correct 211 ms 2024 KB Output is correct
15 Correct 223 ms 2072 KB Output is correct
16 Correct 220 ms 2236 KB Output is correct
17 Correct 223 ms 1936 KB Output is correct
18 Correct 129 ms 1876 KB Output is correct
19 Correct 582 ms 27084 KB Output is correct
20 Correct 473 ms 29760 KB Output is correct
21 Correct 575 ms 29132 KB Output is correct
22 Correct 647 ms 27192 KB Output is correct
23 Correct 340 ms 4704 KB Output is correct
24 Correct 354 ms 4592 KB Output is correct
25 Correct 583 ms 30764 KB Output is correct
26 Correct 674 ms 30940 KB Output is correct
27 Correct 334 ms 6816 KB Output is correct
28 Correct 363 ms 7164 KB Output is correct
29 Correct 336 ms 7012 KB Output is correct
30 Correct 299 ms 4000 KB Output is correct
31 Correct 346 ms 7100 KB Output is correct
32 Correct 385 ms 7540 KB Output is correct
33 Correct 349 ms 4452 KB Output is correct
34 Correct 484 ms 23296 KB Output is correct
35 Correct 657 ms 24516 KB Output is correct
36 Correct 385 ms 4692 KB Output is correct
37 Correct 387 ms 4656 KB Output is correct
38 Correct 238 ms 22232 KB Output is correct
39 Correct 333 ms 22852 KB Output is correct
40 Correct 704 ms 22224 KB Output is correct
41 Correct 268 ms 22840 KB Output is correct
42 Correct 139 ms 22080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 852 KB Output is correct
2 Correct 251 ms 944 KB Output is correct
3 Correct 171 ms 1004 KB Output is correct
4 Correct 191 ms 884 KB Output is correct
5 Correct 192 ms 2228 KB Output is correct
6 Correct 195 ms 1872 KB Output is correct
7 Correct 195 ms 1876 KB Output is correct
8 Correct 202 ms 1924 KB Output is correct
9 Correct 209 ms 1876 KB Output is correct
10 Correct 214 ms 1872 KB Output is correct
11 Correct 219 ms 1876 KB Output is correct
12 Correct 214 ms 2024 KB Output is correct
13 Correct 220 ms 1876 KB Output is correct
14 Correct 211 ms 2024 KB Output is correct
15 Correct 223 ms 2072 KB Output is correct
16 Correct 220 ms 2236 KB Output is correct
17 Correct 223 ms 1936 KB Output is correct
18 Correct 129 ms 1876 KB Output is correct
19 Correct 880 ms 2128 KB Output is correct
20 Correct 593 ms 2388 KB Output is correct
21 Correct 350 ms 1944 KB Output is correct
22 Correct 300 ms 1880 KB Output is correct
23 Correct 346 ms 2032 KB Output is correct
24 Correct 344 ms 1988 KB Output is correct
25 Correct 352 ms 1908 KB Output is correct
26 Correct 325 ms 1908 KB Output is correct
27 Correct 354 ms 2036 KB Output is correct
28 Correct 336 ms 1848 KB Output is correct
29 Correct 361 ms 1872 KB Output is correct
30 Correct 318 ms 2036 KB Output is correct
31 Correct 773 ms 2488 KB Output is correct
32 Correct 757 ms 2540 KB Output is correct
33 Correct 807 ms 2384 KB Output is correct
34 Correct 685 ms 852 KB Output is correct
35 Correct 778 ms 1120 KB Output is correct
36 Correct 811 ms 1068 KB Output is correct
37 Correct 793 ms 1116 KB Output is correct
38 Correct 811 ms 1312 KB Output is correct
39 Correct 789 ms 1328 KB Output is correct
40 Correct 805 ms 1104 KB Output is correct
41 Correct 807 ms 1108 KB Output is correct
42 Correct 802 ms 1108 KB Output is correct
43 Correct 737 ms 1248 KB Output is correct
44 Correct 802 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 852 KB Output is correct
2 Correct 251 ms 944 KB Output is correct
3 Correct 171 ms 1004 KB Output is correct
4 Correct 191 ms 884 KB Output is correct
5 Correct 192 ms 2228 KB Output is correct
6 Correct 195 ms 1872 KB Output is correct
7 Correct 195 ms 1876 KB Output is correct
8 Correct 202 ms 1924 KB Output is correct
9 Correct 209 ms 1876 KB Output is correct
10 Correct 214 ms 1872 KB Output is correct
11 Correct 219 ms 1876 KB Output is correct
12 Correct 214 ms 2024 KB Output is correct
13 Correct 220 ms 1876 KB Output is correct
14 Correct 211 ms 2024 KB Output is correct
15 Correct 223 ms 2072 KB Output is correct
16 Correct 220 ms 2236 KB Output is correct
17 Correct 223 ms 1936 KB Output is correct
18 Correct 129 ms 1876 KB Output is correct
19 Correct 582 ms 27084 KB Output is correct
20 Correct 473 ms 29760 KB Output is correct
21 Correct 575 ms 29132 KB Output is correct
22 Correct 647 ms 27192 KB Output is correct
23 Correct 340 ms 4704 KB Output is correct
24 Correct 354 ms 4592 KB Output is correct
25 Correct 583 ms 30764 KB Output is correct
26 Correct 674 ms 30940 KB Output is correct
27 Correct 334 ms 6816 KB Output is correct
28 Correct 363 ms 7164 KB Output is correct
29 Correct 336 ms 7012 KB Output is correct
30 Correct 299 ms 4000 KB Output is correct
31 Correct 346 ms 7100 KB Output is correct
32 Correct 385 ms 7540 KB Output is correct
33 Correct 349 ms 4452 KB Output is correct
34 Correct 484 ms 23296 KB Output is correct
35 Correct 657 ms 24516 KB Output is correct
36 Correct 385 ms 4692 KB Output is correct
37 Correct 387 ms 4656 KB Output is correct
38 Correct 238 ms 22232 KB Output is correct
39 Correct 333 ms 22852 KB Output is correct
40 Correct 704 ms 22224 KB Output is correct
41 Correct 268 ms 22840 KB Output is correct
42 Correct 139 ms 22080 KB Output is correct
43 Correct 880 ms 2128 KB Output is correct
44 Correct 593 ms 2388 KB Output is correct
45 Correct 350 ms 1944 KB Output is correct
46 Correct 300 ms 1880 KB Output is correct
47 Correct 346 ms 2032 KB Output is correct
48 Correct 344 ms 1988 KB Output is correct
49 Correct 352 ms 1908 KB Output is correct
50 Correct 325 ms 1908 KB Output is correct
51 Correct 354 ms 2036 KB Output is correct
52 Correct 336 ms 1848 KB Output is correct
53 Correct 361 ms 1872 KB Output is correct
54 Correct 318 ms 2036 KB Output is correct
55 Correct 773 ms 2488 KB Output is correct
56 Correct 757 ms 2540 KB Output is correct
57 Correct 807 ms 2384 KB Output is correct
58 Correct 685 ms 852 KB Output is correct
59 Correct 778 ms 1120 KB Output is correct
60 Correct 811 ms 1068 KB Output is correct
61 Correct 793 ms 1116 KB Output is correct
62 Correct 811 ms 1312 KB Output is correct
63 Correct 789 ms 1328 KB Output is correct
64 Correct 805 ms 1104 KB Output is correct
65 Correct 807 ms 1108 KB Output is correct
66 Correct 802 ms 1108 KB Output is correct
67 Correct 737 ms 1248 KB Output is correct
68 Correct 802 ms 1364 KB Output is correct
69 Correct 4643 ms 124924 KB Output is correct
70 Correct 3744 ms 142228 KB Output is correct
71 Correct 785 ms 6052 KB Output is correct
72 Correct 775 ms 6080 KB Output is correct
73 Correct 796 ms 6504 KB Output is correct
74 Correct 1736 ms 49684 KB Output is correct
75 Correct 750 ms 6328 KB Output is correct
76 Correct 2130 ms 58308 KB Output is correct
77 Correct 1706 ms 49044 KB Output is correct
78 Correct 781 ms 6272 KB Output is correct
79 Correct 795 ms 6228 KB Output is correct
80 Correct 5639 ms 106744 KB Output is correct
81 Correct 2114 ms 10652 KB Output is correct
82 Execution timed out 7061 ms 148964 KB Time limit exceeded
83 Halted 0 ms 0 KB -