제출 #482080

#제출 시각아이디문제언어결과실행 시간메모리
482080Yazan_AlattarTable Tennis (info1cup20_tabletennis)C++14
100 / 100
314 ms33776 KiB
#include <iostream> #include <fstream> #include <vector> #include <cstring> #include <algorithm> #include <set> #include <map> #include <queue> #include <list> #include <utility> #include <cmath> #include <numeric> using namespace std; typedef long long ll; #define F first #define S second #define pb push_back #define endl "\n" #define all(x) x.begin(), x.end() const int M = 151007; const ll inf = 1e18; const ll mod = 1e9 + 7; const double pi = acos(-1); const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; vector <int> v; int n, k, a[M]; int solve(int sum) { v.clear(); int l = 1, r = n + k; while(l < r){ if(v.size() == n) break; if(a[l] + a[r] == sum){ v.pb(l); v.pb(r); ++l; --r; } else if(a[l] + a[r] > sum) --r; else ++l; } return ((int)v.size() == n); } int main() { scanf("%d%d", &n, &k); for(int i = 1; i <= n + k; ++i) scanf("%d", &a[i]); sort(a + 1, a + n + k + 1); int res = 0; if(n <= 4 * k){ for(int i = 1; i <= n + k; ++i){ for(int j = i + 1; j <= n + k; ++j){ res = solve(a[i] + a[j]); if(res) break; } if(res) break; } } else{ map <int,int> cnt; for(int i = 1; i <= 2 * k; ++i) for(int j = n - k; j <= n + k; ++j) ++cnt[a[i] + a[j]]; for(auto i : cnt){ if(i.S >= k){ res = solve(i.F); if(res) break; } } } sort(all(v)); for(auto i : v) printf("%d ", a[i]); printf("\n"); return 0; } // Don't forget special cases. (n = 1?) // Look for the constraints. (Runtime array? overflow?)

컴파일 시 표준 에러 (stderr) 메시지

tabletennis.cpp: In function 'int solve(int)':
tabletennis.cpp:34:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |         if(v.size() == n) break;
      |            ~~~~~~~~~^~~~
tabletennis.cpp: In function 'int main()':
tabletennis.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     scanf("%d%d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~
tabletennis.cpp:50:42: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |     for(int i = 1; i <= n + k; ++i) scanf("%d", &a[i]);
      |                                     ~~~~~^~~~~~~~~~~~~
#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...