답안 #1099861

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1099861 2024-10-12T05:38:46 Z model_code 상형문자열 (IOI24_hieroglyphs) C++17
18 / 100
185 ms 14624 KB
// incorrect/yiping-cnt3.cpp

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

struct BIT
{
	int n;
	vector<int> tree;
	#define lowbit(x) ((x)&-(x))
	BIT(int _n)
	{
		n = _n;
		tree = vector<int>(n+1);
	}
	void update(int x,int k)
	{
		++x;
		while(x<=n)
			tree[x] += k, x += lowbit(x);
	}
	int query(int x)
	{
		++x;
		int res = 0;
		while(x)
			res += tree[x], x ^= lowbit(x);
		return res;
	}
	int query(int l,int r)
	{
		return query(r) - query(l-1);
	}
};

vector<int> remove_useless(vector<int> a,vector<int> b)
{
	vector<int> res;
	set<int> bak(b.begin(), b.end());
	for(auto t: a) if(bak.count(t))
		res.emplace_back(t);
	return res;
}

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)
{
	a = remove_useless(a, b);
	b = remove_useless(b, a);
	
	vector<int> dsc = a;
	sort(dsc.begin(), dsc.end());
	dsc.erase(unique(dsc.begin(), dsc.end()), dsc.end());
	
	int d = (int)dsc.size();
	auto getdsc = [&] (int x)
	{
		return lower_bound(dsc.begin(), dsc.end(), x) - dsc.begin();
	};
	
	for(auto &t: a)
		t = getdsc(t);
	for(auto &t: b)
		t = getdsc(t);
	
	vector< vector<int> > posA(d), posB(d);
	for(int i=0; i<(int)a.size(); ++i)
		posA[a[i]].emplace_back(i);
	for(int i=0; i<(int)b.size(); ++i)
		posB[b[i]].emplace_back(i);
	
	auto cmp = [&] (int x,int y) -> int
	{
		bool usex = posA[x][0] < posA[y].back() && posB[x][0] < posB[y].back();
		bool usey = posA[y][0] < posA[x].back() && posB[y][0] < posB[x].back();
		if(usex == usey) return -1;
		return usex;
	};
	
	auto getc = [&] (void) -> vector<int>
	{
		vector<int> vecA, vecB;
		for(auto t: a) if(posA[t].size() <= posB[t].size())
			vecA.emplace_back(t);
		for(auto t: b) if(posA[t].size() > posB[t].size())
			vecB.emplace_back(t);
		
		int i = 0, j = 0;
		vector<int> c;
		while(i<(int)vecA.size() && j<(int)vecB.size())
		{
			int t = cmp(vecA[i], vecB[j]);
			if(t == -1) return {-1};
			if(t) c.emplace_back(vecA[i++]);
			else c.emplace_back(vecB[j++]);
		}
		
		while(i<(int)vecA.size()) c.emplace_back(vecA[i++]);
		while(j<(int)vecB.size()) c.emplace_back(vecB[j++]);
		
		return c;
	};
	
	auto c = getc();
	if(c.size() && c[0] == -1) return {-1};
	
	if(!is_subseq(a, c)) return {-1};
	if(!is_subseq(b, c)) return {-1};
	
	// Only the following case is invalid:
	// A: 121
	// B: 212
	
	BIT tree(b.size());
	
	for(int i=0; i<(int)a.size(); ++i)
	{
		int x = a[i];
		if(posA[x].size() == 2)
		{
			if(i == posA[x][0])
				tree.update(posB[x][0], 1);
			else
				tree.update(posB[x][0], -1);
		}
		if(posB[x].size() == 2)
		{
			if(tree.query(posB[x][0], posB[x][1]))
				return {-1};
		}
	}
	
	for(auto &t: c)
		t = dsc[t];
	
	return c;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 412 KB Output is correct
5 Correct 179 ms 14612 KB Output is correct
6 Correct 185 ms 14624 KB Output is correct
7 Correct 148 ms 14624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 412 KB Output is correct
5 Correct 179 ms 14612 KB Output is correct
6 Correct 185 ms 14624 KB Output is correct
7 Correct 148 ms 14624 KB Output is correct
8 Correct 120 ms 9472 KB Output is correct
9 Correct 126 ms 9396 KB Output is correct
10 Correct 130 ms 9284 KB Output is correct
11 Correct 124 ms 9484 KB Output is correct
12 Correct 118 ms 9292 KB Output is correct
13 Correct 118 ms 9292 KB Output is correct
14 Correct 115 ms 9468 KB Output is correct
15 Correct 114 ms 9292 KB Output is correct
16 Correct 111 ms 9288 KB Output is correct
17 Correct 112 ms 9356 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 53 ms 4348 KB Output is correct
23 Correct 107 ms 7088 KB Output is correct
24 Correct 105 ms 6928 KB Output is correct
25 Correct 96 ms 6924 KB Output is correct
26 Correct 64 ms 4700 KB Output is correct
27 Correct 133 ms 9344 KB Output is correct
28 Correct 143 ms 9292 KB Output is correct
29 Correct 120 ms 9308 KB Output is correct
30 Correct 113 ms 9260 KB Output is correct
31 Correct 127 ms 9292 KB Output is correct
32 Correct 121 ms 9328 KB Output is correct
33 Correct 111 ms 9292 KB Output is correct
34 Correct 97 ms 8264 KB Output is correct
35 Correct 121 ms 9252 KB Output is correct
36 Correct 110 ms 9420 KB Output is correct
37 Correct 122 ms 9316 KB Output is correct
38 Correct 125 ms 9272 KB Output is correct
39 Correct 119 ms 9272 KB Output is correct
40 Correct 126 ms 9568 KB Output is correct
41 Correct 120 ms 9284 KB Output is correct
42 Correct 123 ms 9212 KB Output is correct
43 Correct 110 ms 9032 KB Output is correct
44 Correct 122 ms 9444 KB Output is correct
45 Correct 126 ms 9292 KB Output is correct
46 Correct 154 ms 9036 KB Output is correct
47 Correct 118 ms 9296 KB Output is correct
48 Correct 112 ms 9012 KB Output is correct
49 Correct 111 ms 9288 KB Output is correct
50 Correct 124 ms 9288 KB Output is correct
51 Correct 114 ms 9464 KB Output is correct
52 Correct 127 ms 9292 KB Output is correct
53 Correct 101 ms 9292 KB Output is correct
54 Correct 103 ms 9284 KB Output is correct
55 Correct 99 ms 9288 KB Output is correct
56 Correct 112 ms 9288 KB Output is correct
57 Correct 107 ms 9308 KB Output is correct
58 Correct 102 ms 9324 KB Output is correct
59 Correct 97 ms 9448 KB Output is correct
60 Correct 104 ms 9256 KB Output is correct
61 Correct 109 ms 9408 KB Output is correct
62 Correct 131 ms 9292 KB Output is correct
63 Correct 104 ms 9400 KB Output is correct
64 Correct 108 ms 9036 KB Output is correct
65 Correct 145 ms 9324 KB Output is correct
66 Correct 109 ms 9320 KB Output is correct
67 Correct 154 ms 9288 KB Output is correct
68 Correct 113 ms 9256 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 4376 KB Output is correct
2 Incorrect 22 ms 4016 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 9472 KB Output is correct
2 Correct 126 ms 9396 KB Output is correct
3 Correct 130 ms 9284 KB Output is correct
4 Correct 124 ms 9484 KB Output is correct
5 Correct 118 ms 9292 KB Output is correct
6 Correct 118 ms 9292 KB Output is correct
7 Correct 115 ms 9468 KB Output is correct
8 Correct 114 ms 9292 KB Output is correct
9 Correct 111 ms 9288 KB Output is correct
10 Correct 112 ms 9356 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 53 ms 4348 KB Output is correct
16 Correct 107 ms 7088 KB Output is correct
17 Correct 105 ms 6928 KB Output is correct
18 Correct 96 ms 6924 KB Output is correct
19 Correct 64 ms 4700 KB Output is correct
20 Correct 39 ms 4376 KB Output is correct
21 Incorrect 22 ms 4016 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -