답안 #762954

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
762954 2023-06-22T01:43:53 Z Antonn_114 Just Long Neckties (JOI20_ho_t1) C++14
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;

// Write down the limits of the problem here

int main() {
	// Try to avoid cin, cout :)

	int tc = 1; // scanf("%d", &tc);
	while(tc--) {
		/// Your solution here
		int n;
		scanf("%d", &n);
		vector<pair<int, int>> a(n + 1);
		vector<int> b(n);
		for (int i = 0; i < n + 1; i ++){
			scanf("%d", &a[i].first);
			a[i].second = i;
		}
		for (int i = 0; i < n ; i++){
			scanf("%d", &b[i]);
		}
		sort(a.begin(), a.end(), [&](const pair<int, int> &x, const pair<int, int> &y){
			if (x.first != y.first) return x.first < y.first;
			return x.second > y.second;
		});
		sort(b.begin(), b.end());
		vector<int> res(n + 1);
		vector<int> max_diff_cross(n + 1);
		for (int i = n; i >= 1; i--){
			max_diff_cross[i] = abs(a[i].first - b[i - 1]);
			if (i != n) max_diff_cross[i] = max(max_diff_cross[i], max_diff_cross[i + 1]);
		}
		int max_diff_straight = 0;
		for (int i = 0; i <= n; i++){
			res[a[i].second] = max(i != n ? max_diff_cross[i + 1] : 0, max_diff_straight);
			max_diff_straight = max(max_diff_straight, abs(a[i].first - b[i]));
		}
		for (int i = 0; i <= n; i++){
			printf("%d ", res[i]);
		}
	}
	return 0;
}

/*
 * Ermm don't underestimate Div2A, pls...
 * 
 * If there isn't a clear-cut approach for your program, DO NOT CODE YET!
 *
 * Write down some notes for more complicated problems
 * 
 * Also, please, CP isn't supposed to be complicated
 * 
**/

Compilation message

ho_t1.cpp: In function 'int main()':
ho_t1.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
ho_t1.cpp:17:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |    scanf("%d", &a[i].first);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~
ho_t1.cpp:21:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |    scanf("%d", &b[i]);
      |    ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -