Submission #65652

# Submission time Handle Problem Language Result Execution time Memory
65652 2018-08-08T11:01:25 Z sebinkim None (KOI18_matrix) C++14
100 / 100
665 ms 31316 KB
#include <bits/stdc++.h>

using namespace std;

typedef pair <int, int> pii;

vector <int> V;
set <pii> S[202020];
int A[202020], B[202020], C[202020];
int K[202020], L[202020];
int n, m, ans;

int get_lis(int* T)
{
	int i, k;
	
	for(i=1; i<=n; i++){
		k = lower_bound(L, L+ans+1, T[i]) - L;
		if(k > ans) ans = k;
		L[k] = T[i];
	}
}

bool check(int k, pii p)
{
	auto it = S[k].lower_bound(p);
	if(it == S[k].begin()) return false;
	else{
		it --;
		return it->second < p.second;
	}
}

void push(int k, pii p)
{
	for(; ; ){
		auto it = S[k].lower_bound(p);
		if(it == S[k].end()){
			S[k].insert(p);
			return;
		}
		else{
			if(it->second > p.second) S[k].erase(it);
			else{
				S[k].insert(p);
				return;
			}
		}
	}
}

int main()
{
	int i, b, c, s, e, mid;
	
	scanf("%d%d", &m, &n);
	
	for(i=1; i<=n; i++){
		scanf("%d", A+i);
		V.push_back(A[i]);
	}
	
	sort(V.begin(), V.end());
	V.erase(unique(V.begin(), V.end()), V.end());
	
	for(i=1; i<=n; i++){
		K[i] = lower_bound(V.begin(), V.end(), A[i]) - V.begin() + 1;
	}
	
	V.clear();
	
	for(i=1; i<=n; i++){
		scanf("%d", B+K[i]);
		V.push_back(B[K[i]]);
	}
	
	sort(V.begin(), V.end());
	V.erase(unique(V.begin(), V.end()), V.end());
	
	for(i=1; i<=n; i++){
		B[i] = lower_bound(V.begin(), V.end(), B[i]) - V.begin() + 1;
	}
	
	if(m == 2){
		get_lis(B);
		printf("%d\n", ans);
		return 0;
	}
	
	V.clear();
	
	for(i=1; i<=n; i++){
		scanf("%d", C+K[i]);
		V.push_back(C[K[i]]);
	}
	
	sort(V.begin(), V.end());
	V.erase(unique(V.begin(), V.end()), V.end());
	
	for(i=1; i<=n; i++){
		C[i] = lower_bound(V.begin(), V.end(), C[i]) - V.begin() + 1;
	}
	
	S[0].insert(pii(0, 0));
	
	for(i=1; i<=n; i++){
		b = B[i], c = C[i];
		for(s=0,e=ans;s<=e;){
			mid = s+e >> 1;
			if(check(mid, pii(b, c))) s = mid + 1;
			else e = mid - 1;
		}
		if(s > ans) ans = s;
		push(s, pii(b, c));
	}
	
	printf("%d\n", ans);
	
	return 0;
}

Compilation message

matrix.cpp: In function 'int get_lis(int*)':
matrix.cpp:22:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
matrix.cpp: In function 'int main()':
matrix.cpp:109:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    mid = s+e >> 1;
          ~^~
matrix.cpp:56:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &m, &n);
  ~~~~~^~~~~~~~~~~~~~~~
matrix.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", A+i);
   ~~~~~^~~~~~~~~~~
matrix.cpp:73:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", B+K[i]);
   ~~~~~^~~~~~~~~~~~~~
matrix.cpp:93:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", C+K[i]);
   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 19 ms 10232 KB Output is correct
2 Correct 23 ms 10392 KB Output is correct
3 Correct 20 ms 10776 KB Output is correct
4 Correct 19 ms 10808 KB Output is correct
5 Correct 23 ms 11188 KB Output is correct
6 Correct 19 ms 11548 KB Output is correct
7 Correct 27 ms 11552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 11720 KB Output is correct
2 Correct 26 ms 11848 KB Output is correct
3 Correct 27 ms 11848 KB Output is correct
4 Correct 26 ms 11848 KB Output is correct
5 Correct 28 ms 11848 KB Output is correct
6 Correct 27 ms 11976 KB Output is correct
7 Correct 26 ms 11976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 10232 KB Output is correct
2 Correct 23 ms 10392 KB Output is correct
3 Correct 20 ms 10776 KB Output is correct
4 Correct 19 ms 10808 KB Output is correct
5 Correct 23 ms 11188 KB Output is correct
6 Correct 19 ms 11548 KB Output is correct
7 Correct 27 ms 11552 KB Output is correct
8 Correct 210 ms 14932 KB Output is correct
9 Correct 202 ms 14932 KB Output is correct
10 Correct 208 ms 15108 KB Output is correct
11 Correct 199 ms 15108 KB Output is correct
12 Correct 247 ms 15108 KB Output is correct
13 Correct 203 ms 15368 KB Output is correct
14 Correct 207 ms 15368 KB Output is correct
15 Correct 223 ms 15368 KB Output is correct
16 Correct 280 ms 15840 KB Output is correct
17 Correct 232 ms 15840 KB Output is correct
18 Correct 239 ms 15840 KB Output is correct
19 Correct 231 ms 15840 KB Output is correct
20 Correct 253 ms 15840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 11720 KB Output is correct
2 Correct 26 ms 11848 KB Output is correct
3 Correct 27 ms 11848 KB Output is correct
4 Correct 26 ms 11848 KB Output is correct
5 Correct 28 ms 11848 KB Output is correct
6 Correct 27 ms 11976 KB Output is correct
7 Correct 26 ms 11976 KB Output is correct
8 Correct 411 ms 23516 KB Output is correct
9 Correct 449 ms 24988 KB Output is correct
10 Correct 415 ms 28736 KB Output is correct
11 Correct 307 ms 31192 KB Output is correct
12 Correct 359 ms 31192 KB Output is correct
13 Correct 337 ms 31192 KB Output is correct
14 Correct 387 ms 31192 KB Output is correct
15 Correct 374 ms 31192 KB Output is correct
16 Correct 300 ms 31192 KB Output is correct
17 Correct 381 ms 31192 KB Output is correct
18 Correct 468 ms 31192 KB Output is correct
19 Correct 326 ms 31192 KB Output is correct
20 Correct 387 ms 31192 KB Output is correct
21 Correct 318 ms 31192 KB Output is correct
22 Correct 523 ms 31192 KB Output is correct
23 Correct 411 ms 31192 KB Output is correct
24 Correct 328 ms 31192 KB Output is correct
25 Correct 544 ms 31192 KB Output is correct
26 Correct 665 ms 31304 KB Output is correct
27 Correct 354 ms 31304 KB Output is correct
28 Correct 356 ms 31304 KB Output is correct
29 Correct 376 ms 31304 KB Output is correct
30 Correct 419 ms 31304 KB Output is correct
31 Correct 568 ms 31316 KB Output is correct
32 Correct 384 ms 31316 KB Output is correct