답안 #329704

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
329704 2020-11-22T06:03:31 Z egod1537 조화행렬 (KOI18_matrix) C++14
29 / 100
86 ms 17260 KB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pi;

struct Tuple {
	int a, b, c;
};
bool operator<(const Tuple& t1, const Tuple& t2) {
	if (t1.a != t2.a) return t1.a < t2.a;
	if (t1.b != t2.b) return t1.b < t2.b;
	return t1.c < t2.c;
}

vector<Tuple> arr;

int maxlis = 0;
int dp[200001];
//lis 그래프
struct Graph {
	set<pi> g[200001];

	void insert(int k, pi p) {
		if (g[k].empty()) g[k].insert(p);
		else {
			auto pos = g[k].lower_bound(p);
			
			//prev가 없을 때
			if (pos == g[k].begin()) pos = (g[k].insert(p)).first;
			else {
				auto back = prev(pos);
				if (back->second > p.second) {
					if (back->first == p.first) g[k].erase(pos);
					pos = (g[k].insert(p)).first;
				}
			}

			if (pos != g[k].end()) {
				while (next(pos) != g[k].end()) {
					auto nxt = next(pos);
					if (pos->second <= nxt->second) g[k].erase(nxt);
					else break;
				}
			}
		}
	}
	bool ok(int k, pi p) {
		if (g[k].empty()) return true;

		auto pos = prev(g[k].upper_bound(p));
		if (pos == g[k].end()) return false;
		return pos->second <= p.second;
	}
}g;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	//while (true) {
	//	int t, a, b; cin >> t>> a >> b;
	//	if (t == 0) {
	//		g.insert(0, { a, b });
	//		for (pi p : g.g[0])
	//			cout << "graph : " << p.first << " " << p.second << "\n";
	//	}
	//	else {
	//		cout << "ok : " << g.ok(0, {a, b}) << "\n";
	//	}
	//}

	int n, m; cin >> n >> m;
	arr.resize(m);
	for (int i = 0; i < m; i++) cin >> arr[i].a;
	for (int i = 0; i < m; i++) cin >> arr[i].b;
	if (n == 3) for (int i = 0; i < m; i++) cin >> arr[i].c;

	sort(arr.begin(), arr.end());

	if (n == 2) {
		vector<int> dp;
		for (int i = 0; i < m; i++) {
			int idx = lower_bound(dp.begin(), dp.end(), arr[i].b) - dp.begin();
			if (idx == dp.size()) dp.push_back(arr[i].b);
			else dp[idx] = arr[i].b;
		}
		cout << dp.size();
	}
	else {
		int ans = 0;

		for (int i = 0; i < m; i++) {
			pi now = { arr[i].b, arr[i].c };

			//어떤 mid_lis가 가능하면 0 ~ mid lis가 가능하므로
			int lo = 0, hi = maxlis;
			while (lo <= hi) {
				int mid = (lo + hi) / 2;

				if (g.ok(mid, now)) lo = mid + 1;
				else hi = mid - 1;
			}

			//cout << now.first << " " << now.second << " " << lo << "\n";

			dp[i] = lo;
			g.insert(dp[i], now);
			ans = max(ans, dp[i]);
			maxlis = max(maxlis, dp[i]);
		}

		cout << ans;
	}

	return 0;
}

Compilation message

matrix.cpp: In function 'int main()':
matrix.cpp:85:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |    if (idx == dp.size()) dp.push_back(arr[i].b);
      |        ~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 10092 KB Output is correct
2 Correct 10 ms 10092 KB Output is correct
3 Correct 11 ms 10112 KB Output is correct
4 Correct 10 ms 10092 KB Output is correct
5 Correct 11 ms 10092 KB Output is correct
6 Correct 10 ms 10092 KB Output is correct
7 Correct 10 ms 10092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 10476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 10092 KB Output is correct
2 Correct 10 ms 10092 KB Output is correct
3 Correct 11 ms 10112 KB Output is correct
4 Correct 10 ms 10092 KB Output is correct
5 Correct 11 ms 10092 KB Output is correct
6 Correct 10 ms 10092 KB Output is correct
7 Correct 10 ms 10092 KB Output is correct
8 Correct 86 ms 15980 KB Output is correct
9 Correct 85 ms 15980 KB Output is correct
10 Correct 82 ms 16364 KB Output is correct
11 Correct 75 ms 15980 KB Output is correct
12 Correct 85 ms 15980 KB Output is correct
13 Correct 83 ms 16624 KB Output is correct
14 Correct 86 ms 16108 KB Output is correct
15 Correct 74 ms 15980 KB Output is correct
16 Correct 79 ms 17260 KB Output is correct
17 Correct 82 ms 16624 KB Output is correct
18 Correct 79 ms 16624 KB Output is correct
19 Correct 82 ms 16236 KB Output is correct
20 Correct 86 ms 15980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 10476 KB Output isn't correct
2 Halted 0 ms 0 KB -