Submission #1099846

# Submission time Handle Problem Language Result Execution time Memory
1099846 2024-10-12T05:35:49 Z model_code Hieroglyphs (IOI24_hieroglyphs) C++17
29 / 100
182 ms 26284 KB
// incorrect/yiping-wa2.cpp

#include<bits/stdc++.h>
#include"hieroglyphs.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

struct Data
{
	int d;
	vector<int> a, cnt, rnk;
	vector< vector<int> > pos;
	
	Data(vector<int> _a, int _d)
	{
		a = _a; d = _d;
		cnt.resize(d); pos.resize(d); rnk.resize(a.size());
		for(int i=0; i<(int)a.size(); ++i)
		{
			int x = a[i];
			rnk[i] = cnt[x]; ++cnt[x];
			pos[x].emplace_back(i);
		}
	}
	bool check(int x,int cx,int y,int cy) const
	{
		if(cx > (int)pos[x].size() || cy > (int)pos[y].size())
			return 0;
		if(cx == 0 || cy == 0) return 1;
		return pos[x][cx - 1] < pos[y][(int)pos[y].size() - cy];
	}
	int get_next(int i,int x) const
	{
		auto it = lower_bound(pos[x].begin(), pos[x].end(), i);
		return it == pos[x].end()? (int)a.size(): *it;
	}
};

vector<int> get_cand(const Data &aa, const Data &bb)
{
	int d = aa.d;
	vector<int> type(d), need(d);
	for(int i=0; i<d; ++i)
	{
		type[i] = aa.cnt[i] <= bb.cnt[i]? 0: 1;
		need[i] = min(aa.cnt[i], bb.cnt[i]);
	}
	
	vector<pii> veca, vecb;
	for(int i=0; i<(int)aa.a.size(); ++i)
		if(type[aa.a[i]] == 0)
			veca.emplace_back(aa.a[i], aa.rnk[i]);
	for(int i=0; i<(int)bb.a.size(); ++i)
		if(type[bb.a[i]] == 1)
			vecb.emplace_back(bb.a[i], bb.rnk[i]);
	
	auto check = [&] (pii x,pii y)
	{
		return aa.check(x.first, x.second + 1, y.first, need[y.first] - y.second)
		    && bb.check(x.first, x.second + 1, y.first, need[y.first] - y.second);
	};
	
	vector<int> c;
	int i = 0, j = 0;
	while(i<(int)veca.size() && j<(int)vecb.size())
	{
		bool tx = check(veca[i], vecb[j]);
		bool ty = check(vecb[j], veca[i]);
		
		if(tx == ty) return {-1};
		
		if(tx) c.emplace_back(veca[i].first), ++i;
		else c.emplace_back(vecb[j].first), ++j;
	}
	
	while(i<(int)veca.size()) c.emplace_back(veca[i].first), ++i;
	while(j<(int)vecb.size()) c.emplace_back(vecb[j].first), ++j;
	
	return c;
}

bool is_invalid(const vector<int> &c)
{
	return c.size() == 1 && c[0] == -1;
}

bool is_subseq(const vector<int> &a, const vector<int> &c)
{
	int j = 0;
	for(int i=0; i<(int)a.size() && j<(int)c.size(); ++i)
		if(a[i] == c[j]) ++j;
	return j >= (int)c.size();
}

vector<int> ucs(vector<int> a, vector<int> b)
{
	int d = 0;
	for(auto t: a)
		d = max(d, t + 1);
	for(auto t: b)
		d = max(d, t + 1);
	
	Data aa(a, d), bb(b, d);
	
	auto c = get_cand(aa, bb);
	if(is_invalid(c)) return c;
	
	if(!is_subseq(a, c)) return {-1};
	if(!is_subseq(b, c)) return {-1};
	
	Data cc(c, d);
	
	const int LIM = 100;
	
	vector< vector<int> > dp(LIM+1, vector<int>(LIM+1));
	
	int lst = 0;
	
	for(int al=0,ar, bl=0,br; al<(int)a.size() && bl<(int)b.size(); al=ar, bl=br)
	{
		ar = min((int)a.size(), al + LIM);
		br = min((int)b.size(), bl + LIM);
		
		for(int i=0; i<LIM; ++i)
			fill(dp[i].begin(), dp[i].end(), lst);
		
		for(int i=0; i<=ar-al; ++i)
			for(int j=0; j<=br-bl; ++j)
			{
				if(i) dp[i][j] = max(dp[i][j], dp[i-1][j]);
				if(j) dp[i][j] = max(dp[i][j], dp[i][j-1]);
				if(i && j && a[al+i-1] == b[bl+j-1])
				{
					dp[i][j] = max(dp[i][j], cc.get_next(dp[i-1][j-1], a[al+i-1]) + 1);
					if(dp[i][j] > (int)c.size())
						return {-1};
				}
			}
		
		lst = dp[ar-al][br-bl];
	}
	
	return c;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 83 ms 22748 KB Output is correct
6 Correct 56 ms 17708 KB Output is correct
7 Correct 36 ms 17616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 83 ms 22748 KB Output is correct
6 Correct 56 ms 17708 KB Output is correct
7 Correct 36 ms 17616 KB Output is correct
8 Correct 105 ms 26272 KB Output is correct
9 Correct 111 ms 26136 KB Output is correct
10 Correct 72 ms 26076 KB Output is correct
11 Correct 108 ms 26068 KB Output is correct
12 Correct 82 ms 26188 KB Output is correct
13 Correct 92 ms 26068 KB Output is correct
14 Correct 128 ms 26064 KB Output is correct
15 Correct 98 ms 26064 KB Output is correct
16 Correct 82 ms 26108 KB Output is correct
17 Correct 97 ms 26100 KB Output is correct
18 Correct 6 ms 16708 KB Output is correct
19 Correct 7 ms 16468 KB Output is correct
20 Correct 8 ms 16952 KB Output is correct
21 Correct 8 ms 17020 KB Output is correct
22 Correct 51 ms 22492 KB Output is correct
23 Correct 86 ms 26284 KB Output is correct
24 Correct 80 ms 26276 KB Output is correct
25 Correct 81 ms 26216 KB Output is correct
26 Correct 63 ms 23348 KB Output is correct
27 Correct 89 ms 26096 KB Output is correct
28 Correct 80 ms 26240 KB Output is correct
29 Correct 54 ms 20464 KB Output is correct
30 Correct 38 ms 20520 KB Output is correct
31 Correct 89 ms 26212 KB Output is correct
32 Incorrect 93 ms 26064 KB Output isn't correct
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 155 ms 6460 KB Output is correct
2 Correct 149 ms 6820 KB Output is correct
3 Correct 113 ms 5652 KB Output is correct
4 Correct 103 ms 5488 KB Output is correct
5 Correct 128 ms 6284 KB Output is correct
6 Correct 20 ms 3288 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 155 ms 6600 KB Output is correct
17 Correct 14 ms 6220 KB Output is correct
18 Correct 91 ms 4284 KB Output is correct
19 Correct 13 ms 4160 KB Output is correct
20 Correct 85 ms 5328 KB Output is correct
21 Correct 12 ms 4668 KB Output is correct
22 Correct 16 ms 6076 KB Output is correct
23 Correct 15 ms 5836 KB Output is correct
24 Correct 24 ms 5820 KB Output is correct
25 Correct 15 ms 6216 KB Output is correct
26 Correct 26 ms 5828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 26272 KB Output is correct
2 Correct 111 ms 26136 KB Output is correct
3 Correct 72 ms 26076 KB Output is correct
4 Correct 108 ms 26068 KB Output is correct
5 Correct 82 ms 26188 KB Output is correct
6 Correct 92 ms 26068 KB Output is correct
7 Correct 128 ms 26064 KB Output is correct
8 Correct 98 ms 26064 KB Output is correct
9 Correct 82 ms 26108 KB Output is correct
10 Correct 97 ms 26100 KB Output is correct
11 Correct 6 ms 16708 KB Output is correct
12 Correct 7 ms 16468 KB Output is correct
13 Correct 8 ms 16952 KB Output is correct
14 Correct 8 ms 17020 KB Output is correct
15 Correct 51 ms 22492 KB Output is correct
16 Correct 86 ms 26284 KB Output is correct
17 Correct 80 ms 26276 KB Output is correct
18 Correct 81 ms 26216 KB Output is correct
19 Correct 63 ms 23348 KB Output is correct
20 Correct 155 ms 6460 KB Output is correct
21 Correct 149 ms 6820 KB Output is correct
22 Correct 113 ms 5652 KB Output is correct
23 Correct 103 ms 5488 KB Output is correct
24 Correct 128 ms 6284 KB Output is correct
25 Correct 20 ms 3288 KB Output is correct
26 Correct 12 ms 16720 KB Output is correct
27 Correct 8 ms 16716 KB Output is correct
28 Correct 7 ms 14940 KB Output is correct
29 Correct 7 ms 16020 KB Output is correct
30 Correct 6 ms 16816 KB Output is correct
31 Correct 9 ms 16712 KB Output is correct
32 Correct 8 ms 16964 KB Output is correct
33 Correct 8 ms 17016 KB Output is correct
34 Correct 20 ms 17592 KB Output is correct
35 Correct 64 ms 22540 KB Output is correct
36 Correct 66 ms 23048 KB Output is correct
37 Correct 96 ms 23084 KB Output is correct
38 Correct 123 ms 23000 KB Output is correct
39 Correct 182 ms 22960 KB Output is correct
40 Correct 106 ms 24772 KB Output is correct
41 Correct 80 ms 23360 KB Output is correct
42 Correct 53 ms 16736 KB Output is correct
43 Correct 55 ms 18344 KB Output is correct
44 Correct 59 ms 18048 KB Output is correct
45 Correct 49 ms 16644 KB Output is correct
46 Correct 76 ms 23784 KB Output is correct
47 Correct 86 ms 23700 KB Output is correct
48 Correct 74 ms 23548 KB Output is correct
49 Correct 74 ms 23344 KB Output is correct
50 Correct 82 ms 23284 KB Output is correct
51 Correct 72 ms 23376 KB Output is correct
52 Correct 69 ms 23432 KB Output is correct
53 Correct 96 ms 23292 KB Output is correct
54 Correct 66 ms 23264 KB Output is correct
55 Correct 14 ms 18396 KB Output is correct
56 Correct 67 ms 23008 KB Output is correct
57 Correct 60 ms 22572 KB Output is correct
58 Correct 63 ms 23396 KB Output is correct
59 Correct 84 ms 23180 KB Output is correct
60 Correct 65 ms 23048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 12 ms 16720 KB Output is correct
11 Correct 8 ms 16716 KB Output is correct
12 Correct 7 ms 14940 KB Output is correct
13 Correct 7 ms 16020 KB Output is correct
14 Correct 6 ms 16816 KB Output is correct
15 Correct 9 ms 16712 KB Output is correct
16 Correct 8 ms 16964 KB Output is correct
17 Correct 8 ms 17016 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 3 ms 604 KB Output is correct
21 Correct 2 ms 856 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Incorrect 3 ms 604 KB Output isn't correct
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 83 ms 22748 KB Output is correct
9 Correct 56 ms 17708 KB Output is correct
10 Correct 36 ms 17616 KB Output is correct
11 Correct 105 ms 26272 KB Output is correct
12 Correct 111 ms 26136 KB Output is correct
13 Correct 72 ms 26076 KB Output is correct
14 Correct 108 ms 26068 KB Output is correct
15 Correct 82 ms 26188 KB Output is correct
16 Correct 92 ms 26068 KB Output is correct
17 Correct 128 ms 26064 KB Output is correct
18 Correct 98 ms 26064 KB Output is correct
19 Correct 82 ms 26108 KB Output is correct
20 Correct 97 ms 26100 KB Output is correct
21 Correct 6 ms 16708 KB Output is correct
22 Correct 7 ms 16468 KB Output is correct
23 Correct 8 ms 16952 KB Output is correct
24 Correct 8 ms 17020 KB Output is correct
25 Correct 51 ms 22492 KB Output is correct
26 Correct 86 ms 26284 KB Output is correct
27 Correct 80 ms 26276 KB Output is correct
28 Correct 81 ms 26216 KB Output is correct
29 Correct 63 ms 23348 KB Output is correct
30 Correct 89 ms 26096 KB Output is correct
31 Correct 80 ms 26240 KB Output is correct
32 Correct 54 ms 20464 KB Output is correct
33 Correct 38 ms 20520 KB Output is correct
34 Correct 89 ms 26212 KB Output is correct
35 Incorrect 93 ms 26064 KB Output isn't correct
36 Halted 0 ms 0 KB -