답안 #855604

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
855604 2023-10-01T13:44:42 Z vjudge1 Crossing (JOI21_crossing) C++17
49 / 100
7000 ms 145148 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 221 ms 904 KB Output is correct
2 Correct 251 ms 1152 KB Output is correct
3 Correct 171 ms 852 KB Output is correct
4 Correct 190 ms 848 KB Output is correct
5 Correct 196 ms 944 KB Output is correct
6 Correct 195 ms 784 KB Output is correct
7 Correct 197 ms 976 KB Output is correct
8 Correct 199 ms 928 KB Output is correct
9 Correct 205 ms 1056 KB Output is correct
10 Correct 219 ms 1040 KB Output is correct
11 Correct 238 ms 844 KB Output is correct
12 Correct 214 ms 1040 KB Output is correct
13 Correct 223 ms 1032 KB Output is correct
14 Correct 213 ms 1020 KB Output is correct
15 Correct 219 ms 1040 KB Output is correct
16 Correct 234 ms 1252 KB Output is correct
17 Correct 219 ms 848 KB Output is correct
18 Correct 127 ms 876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 221 ms 904 KB Output is correct
2 Correct 251 ms 1152 KB Output is correct
3 Correct 171 ms 852 KB Output is correct
4 Correct 190 ms 848 KB Output is correct
5 Correct 196 ms 944 KB Output is correct
6 Correct 195 ms 784 KB Output is correct
7 Correct 197 ms 976 KB Output is correct
8 Correct 199 ms 928 KB Output is correct
9 Correct 205 ms 1056 KB Output is correct
10 Correct 219 ms 1040 KB Output is correct
11 Correct 238 ms 844 KB Output is correct
12 Correct 214 ms 1040 KB Output is correct
13 Correct 223 ms 1032 KB Output is correct
14 Correct 213 ms 1020 KB Output is correct
15 Correct 219 ms 1040 KB Output is correct
16 Correct 234 ms 1252 KB Output is correct
17 Correct 219 ms 848 KB Output is correct
18 Correct 127 ms 876 KB Output is correct
19 Correct 588 ms 25100 KB Output is correct
20 Correct 466 ms 26980 KB Output is correct
21 Correct 634 ms 25672 KB Output is correct
22 Correct 633 ms 23688 KB Output is correct
23 Correct 346 ms 2592 KB Output is correct
24 Correct 366 ms 2400 KB Output is correct
25 Correct 613 ms 27268 KB Output is correct
26 Correct 671 ms 27260 KB Output is correct
27 Correct 348 ms 3132 KB Output is correct
28 Correct 360 ms 3328 KB Output is correct
29 Correct 390 ms 3344 KB Output is correct
30 Correct 297 ms 1480 KB Output is correct
31 Correct 349 ms 3376 KB Output is correct
32 Correct 413 ms 4120 KB Output is correct
33 Correct 368 ms 2020 KB Output is correct
34 Correct 497 ms 19316 KB Output is correct
35 Correct 738 ms 21168 KB Output is correct
36 Correct 432 ms 2244 KB Output is correct
37 Correct 381 ms 2304 KB Output is correct
38 Correct 256 ms 18844 KB Output is correct
39 Correct 337 ms 19008 KB Output is correct
40 Correct 797 ms 18524 KB Output is correct
41 Correct 255 ms 19008 KB Output is correct
42 Correct 129 ms 19004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 221 ms 904 KB Output is correct
2 Correct 251 ms 1152 KB Output is correct
3 Correct 171 ms 852 KB Output is correct
4 Correct 190 ms 848 KB Output is correct
5 Correct 196 ms 944 KB Output is correct
6 Correct 195 ms 784 KB Output is correct
7 Correct 197 ms 976 KB Output is correct
8 Correct 199 ms 928 KB Output is correct
9 Correct 205 ms 1056 KB Output is correct
10 Correct 219 ms 1040 KB Output is correct
11 Correct 238 ms 844 KB Output is correct
12 Correct 214 ms 1040 KB Output is correct
13 Correct 223 ms 1032 KB Output is correct
14 Correct 213 ms 1020 KB Output is correct
15 Correct 219 ms 1040 KB Output is correct
16 Correct 234 ms 1252 KB Output is correct
17 Correct 219 ms 848 KB Output is correct
18 Correct 127 ms 876 KB Output is correct
19 Correct 896 ms 1064 KB Output is correct
20 Correct 624 ms 1080 KB Output is correct
21 Correct 390 ms 848 KB Output is correct
22 Correct 305 ms 1016 KB Output is correct
23 Correct 345 ms 1060 KB Output is correct
24 Correct 342 ms 1204 KB Output is correct
25 Correct 366 ms 1064 KB Output is correct
26 Correct 335 ms 956 KB Output is correct
27 Correct 345 ms 848 KB Output is correct
28 Correct 355 ms 860 KB Output is correct
29 Correct 397 ms 1060 KB Output is correct
30 Correct 314 ms 1012 KB Output is correct
31 Correct 794 ms 1140 KB Output is correct
32 Correct 773 ms 1436 KB Output is correct
33 Correct 804 ms 1104 KB Output is correct
34 Correct 700 ms 1040 KB Output is correct
35 Correct 831 ms 1316 KB Output is correct
36 Correct 807 ms 1060 KB Output is correct
37 Correct 786 ms 1104 KB Output is correct
38 Correct 817 ms 1104 KB Output is correct
39 Correct 825 ms 1108 KB Output is correct
40 Correct 799 ms 1108 KB Output is correct
41 Correct 783 ms 1112 KB Output is correct
42 Correct 826 ms 1104 KB Output is correct
43 Correct 746 ms 956 KB Output is correct
44 Correct 822 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 221 ms 904 KB Output is correct
2 Correct 251 ms 1152 KB Output is correct
3 Correct 171 ms 852 KB Output is correct
4 Correct 190 ms 848 KB Output is correct
5 Correct 196 ms 944 KB Output is correct
6 Correct 195 ms 784 KB Output is correct
7 Correct 197 ms 976 KB Output is correct
8 Correct 199 ms 928 KB Output is correct
9 Correct 205 ms 1056 KB Output is correct
10 Correct 219 ms 1040 KB Output is correct
11 Correct 238 ms 844 KB Output is correct
12 Correct 214 ms 1040 KB Output is correct
13 Correct 223 ms 1032 KB Output is correct
14 Correct 213 ms 1020 KB Output is correct
15 Correct 219 ms 1040 KB Output is correct
16 Correct 234 ms 1252 KB Output is correct
17 Correct 219 ms 848 KB Output is correct
18 Correct 127 ms 876 KB Output is correct
19 Correct 588 ms 25100 KB Output is correct
20 Correct 466 ms 26980 KB Output is correct
21 Correct 634 ms 25672 KB Output is correct
22 Correct 633 ms 23688 KB Output is correct
23 Correct 346 ms 2592 KB Output is correct
24 Correct 366 ms 2400 KB Output is correct
25 Correct 613 ms 27268 KB Output is correct
26 Correct 671 ms 27260 KB Output is correct
27 Correct 348 ms 3132 KB Output is correct
28 Correct 360 ms 3328 KB Output is correct
29 Correct 390 ms 3344 KB Output is correct
30 Correct 297 ms 1480 KB Output is correct
31 Correct 349 ms 3376 KB Output is correct
32 Correct 413 ms 4120 KB Output is correct
33 Correct 368 ms 2020 KB Output is correct
34 Correct 497 ms 19316 KB Output is correct
35 Correct 738 ms 21168 KB Output is correct
36 Correct 432 ms 2244 KB Output is correct
37 Correct 381 ms 2304 KB Output is correct
38 Correct 256 ms 18844 KB Output is correct
39 Correct 337 ms 19008 KB Output is correct
40 Correct 797 ms 18524 KB Output is correct
41 Correct 255 ms 19008 KB Output is correct
42 Correct 129 ms 19004 KB Output is correct
43 Correct 896 ms 1064 KB Output is correct
44 Correct 624 ms 1080 KB Output is correct
45 Correct 390 ms 848 KB Output is correct
46 Correct 305 ms 1016 KB Output is correct
47 Correct 345 ms 1060 KB Output is correct
48 Correct 342 ms 1204 KB Output is correct
49 Correct 366 ms 1064 KB Output is correct
50 Correct 335 ms 956 KB Output is correct
51 Correct 345 ms 848 KB Output is correct
52 Correct 355 ms 860 KB Output is correct
53 Correct 397 ms 1060 KB Output is correct
54 Correct 314 ms 1012 KB Output is correct
55 Correct 794 ms 1140 KB Output is correct
56 Correct 773 ms 1436 KB Output is correct
57 Correct 804 ms 1104 KB Output is correct
58 Correct 700 ms 1040 KB Output is correct
59 Correct 831 ms 1316 KB Output is correct
60 Correct 807 ms 1060 KB Output is correct
61 Correct 786 ms 1104 KB Output is correct
62 Correct 817 ms 1104 KB Output is correct
63 Correct 825 ms 1108 KB Output is correct
64 Correct 799 ms 1108 KB Output is correct
65 Correct 783 ms 1112 KB Output is correct
66 Correct 826 ms 1104 KB Output is correct
67 Correct 746 ms 956 KB Output is correct
68 Correct 822 ms 972 KB Output is correct
69 Correct 4538 ms 121592 KB Output is correct
70 Correct 3311 ms 138576 KB Output is correct
71 Correct 796 ms 3664 KB Output is correct
72 Correct 783 ms 3820 KB Output is correct
73 Correct 814 ms 3920 KB Output is correct
74 Correct 2221 ms 46160 KB Output is correct
75 Correct 815 ms 3912 KB Output is correct
76 Correct 2569 ms 54620 KB Output is correct
77 Correct 2017 ms 45660 KB Output is correct
78 Correct 863 ms 3716 KB Output is correct
79 Correct 830 ms 4352 KB Output is correct
80 Correct 5967 ms 103532 KB Output is correct
81 Correct 2317 ms 8140 KB Output is correct
82 Execution timed out 7077 ms 145148 KB Time limit exceeded
83 Halted 0 ms 0 KB -