답안 #972189

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
972189 2024-04-30T08:27:03 Z penguin133 Table Tennis (info1cup20_tabletennis) C++17
49 / 100
29 ms 4324 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, k, A[200005];

void solve(){
	cin >> n >> k;
	for(int i = 1; i <= n + k; i++)cin >> A[i];
	for(int i = 1; i <= k + 1; i++){
		for(int j = n + k; j >= n; j--){
			if(i - 1 + n + k - j > k)continue;
			int l = i + 1, r = j - 1, cnt = 1, tar = A[i] + A[j];
			while(l <= r){
				while(r >= l && A[l] + A[r] > tar)r--;
				if(r <= l || cnt + (r - l + 1) / 2 < n / 2)break;
				if(A[l] + A[r] == tar)cnt++;
				l++;
				r--;
			}
			//cerr << i << ' ' << j << ' ' << cnt << '\n';
			if(cnt >= n / 2){
				vector <int> v;
				v.push_back(A[i]); v.push_back(A[j]);
				l = i + 1, r = j - 1, tar = A[i] + A[j];
				while(l <= r){
					while(r >= l && A[l] + A[r] > tar)r--;
					if(r <= l)break;
					if(A[l] + A[r] == tar && v.size() < n)v.push_back(A[l]), v.push_back(A[r]);
					l++; r--;
				}
				sort(v.begin(), v.end());
				for(auto a : v)cout << a << ' ';
				cout << '\n';
				return;
			}
		}
	}
	assert(0);
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	//cin >> tc;
	for(int tc1=1;tc1<=tc;tc1++){
		// cout << "Case #" << tc1 << ": ";
		solve();
	}
}

Compilation message

tabletennis.cpp: In function 'void solve()':
tabletennis.cpp:38:40: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   38 |      if(A[l] + A[r] == tar && v.size() < n)v.push_back(A[l]), v.push_back(A[r]);
      |                               ~~~~~~~~~^~~
tabletennis.cpp: At global scope:
tabletennis.cpp:51:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   51 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 860 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 4308 KB Output is correct
2 Correct 26 ms 4300 KB Output is correct
3 Correct 29 ms 4300 KB Output is correct
4 Correct 26 ms 4300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Runtime error 1 ms 604 KB Execution killed with signal 6
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 29 ms 4324 KB Output is correct
3 Runtime error 15 ms 2904 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Runtime error 22 ms 2928 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -