제출 #481917

#제출 시각아이디문제언어결과실행 시간메모리
481917Yazan_AlattarTable Tennis (info1cup20_tabletennis)C++14
컴파일 에러
0 ms0 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 = 200007; 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() { ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n >> k; for(int i = 1; i <= n + k; ++i) cin >> a[i]; sort(a + 1, a + n + k + 1); int res = 0; for(int i = 1; i <= 2 * k + 50; ++i){ res = solve(a[i] + a[i + 1]); if(res) break; } if(res) break; } sort(all(v)); for(auto i : v) cout << a[i] << " "; cout << endl; 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:58:17: error: break statement not within loop or switch
   58 |         if(res) break;
      |                 ^~~~~
tabletennis.cpp: At global scope:
tabletennis.cpp:60:9: error: expected constructor, destructor, or type conversion before '(' token
   60 |     sort(all(v));
      |         ^
tabletennis.cpp:61:5: error: expected unqualified-id before 'for'
   61 |     for(auto i : v) cout << a[i] << " ";
      |     ^~~
tabletennis.cpp:62:5: error: 'cout' does not name a type
   62 |     cout << endl;
      |     ^~~~
tabletennis.cpp:63:5: error: expected unqualified-id before 'return'
   63 |     return 0;
      |     ^~~~~~
tabletennis.cpp:64:1: error: expected declaration before '}' token
   64 | }
      | ^