Submission #972185

#TimeUsernameProblemLanguageResultExecution timeMemory
972185penguin133Table Tennis (info1cup20_tabletennis)C++17
24 / 100
3044 ms5844 KiB
#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; 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)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 (stderr)

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(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...