Submission #1055825

# Submission time Handle Problem Language Result Execution time Memory
1055825 2024-08-13T05:53:59 Z 이온조(#11108) Pizza Party (CCO24_day1problem2) C++17
9 / 12
859 ms 101520 KB
#include <bits/stdc++.h>
using namespace std;

int A[1000009], B[1000009], C[1000009], D[1000009], E[1000009], F[1000009], G[1000009];

int get(int x) {
	int r = 0;
	for(int i=x; i>=1; i-=(i&-i)) r = max(r, F[i]);
	return r;
}

void upd(int x, int y) {
	for(int i=x; i<=1000000; i+=(i&-i)) F[i] = max(F[i], y);
}

int main() {
	set<int> st;
	int N; scanf("%d", &N);
	for(int i=N; i>=1; i--) scanf("%d", &A[i]);
	for(int i=1; i<=N; i++) {
		scanf("%d", &B[i]);
		st.insert(B[i]);
		E[B[i]] = i;
		B[i] = i;
	}
	for(int i=1; i<=N; i++) A[i] = E[A[i]];
	if(st.size() != N) return !printf("-1");
	int mx = 0;
	for(int i=N; i>=1; i--) {
		G[i] = get(A[i]) + 1;
		D[A[i]] = G[i];
		mx = max(mx, G[i]);
		upd(A[i], G[i]);
	}
	for(int i=1; i<=N; i++) C[i] = G[N-i+1];
	printf("%d\n", mx);
	for(int i=1; i<=N; i++) printf("%d%c", C[i], i == N ? '\n' : ' ');
	for(int i=1; i<=N; i++) printf("%d%c", D[i], i == N ? '\n' : ' ');
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:27:15: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |  if(st.size() != N) return !printf("-1");
      |     ~~~~~~~~~~^~~~
Main.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |  int N; scanf("%d", &N);
      |         ~~~~~^~~~~~~~~~
Main.cpp:19:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  for(int i=N; i>=1; i--) scanf("%d", &A[i]);
      |                          ~~~~~^~~~~~~~~~~~~
Main.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |   scanf("%d", &B[i]);
      |   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 86 ms 8028 KB jury uses fewer stacks: jans = 2, pans = 1061109567
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 860 KB good job!
2 Correct 1 ms 604 KB good job!
3 Correct 2 ms 860 KB good job!
4 Correct 1 ms 704 KB good job!
5 Correct 2 ms 860 KB good job!
6 Correct 3 ms 604 KB good job!
7 Correct 1 ms 600 KB good job!
8 Correct 4 ms 860 KB good job!
9 Correct 2 ms 860 KB good job!
10 Correct 2 ms 860 KB good job!
11 Correct 2 ms 860 KB good job!
12 Correct 2 ms 916 KB good job!
13 Correct 3 ms 688 KB good job!
14 Correct 2 ms 860 KB good job!
15 Correct 1 ms 604 KB good job!
# Verdict Execution time Memory Grader output
1 Correct 859 ms 83540 KB good job!
2 Correct 698 ms 58932 KB good job!
3 Correct 813 ms 88752 KB good job!
4 Correct 618 ms 61328 KB good job!
5 Correct 788 ms 84564 KB good job!
6 Correct 647 ms 66640 KB good job!
7 Correct 628 ms 60808 KB good job!
8 Correct 801 ms 83528 KB good job!
9 Correct 775 ms 96260 KB good job!
10 Correct 806 ms 96592 KB good job!
11 Correct 788 ms 101520 KB good job!
12 Correct 746 ms 79028 KB good job!
13 Correct 784 ms 88656 KB good job!
14 Correct 762 ms 78948 KB good job!
15 Correct 624 ms 58944 KB good job!
16 Correct 638 ms 59376 KB good job!