제출 #254539

#제출 시각아이디문제언어결과실행 시간메모리
254539MrRobot_28Drvca (COCI19_drvca)C++17
30 / 110
117 ms3184 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int n; vector <bool> used; vector <int> a; int lower(int l, int r, int val) { r++; int r1 = r; while(r - l > 1) { int midd = (r + l) / 2; if(a[midd] < val || a[midd] == val && used[midd]) { l = midd; } else { r = midd; } } if(r1 != r && a[r] == val) { return r; } if(a[l] == val) { return l; } return r; } void funct1() { int diff = a[1] - a[0]; vector <int> vec1; used[0] = 1; vec1.push_back(a[0]); int it1 = 1; for(int j = 1; j < n; j++) { if(it1 == n) { break; } int it = lower(it1, n - 1, vec1.back() + diff); if(it != a.size() && a[it] == vec1.back() + diff) { vec1.push_back(a[it]); used[it] = 1; it1 = it + 1; } else { break; } } vector <int> vec2; for(int j = 0; j < n; j++) { if(!used[j]) { vec2.push_back(a[j]); } } bool flag = true; for(int j = 1; j + 1 < vec2.size(); j++) { if(vec2[j] - vec2[j - 1] != vec2[j + 1] - vec2[j]) { flag = false; } } if(flag && vec2.size() > 0) { cout << vec1.size() << "\n"; for(int i = 0; i < vec1.size(); i++) { cout << vec1[i] << " "; } cout << "\n"; cout << vec2.size() << "\n"; for(int i = 0; i < vec2.size(); i++) { cout << vec2[i] << " "; } exit(0); } for(int i = n - 1; i >= 0; i--) { if(used[i]) { used[i] = 0; break; } } vec1.pop_back(); if(vec1.size() == 0) { return; } vec2.clear(); for(int i = 0; i < n; i++) { if(!used[i]) { vec2.push_back(a[i]); } } flag = true; for(int j = 1; j + 1 < vec2.size(); j++) { if(vec2[j] - vec2[j - 1] != vec2[j + 1] - vec2[j]) { flag = false; } } if(flag) { cout << vec1.size() << "\n"; for(int i = 0; i < vec1.size(); i++) { cout << vec1[i] << " "; } cout << "\n"; cout << vec2.size() << "\n"; for(int i = 0; i < vec2.size(); i++) { cout << vec2[i] << " "; } exit(0); } if(vec1.size() == 1) { return; } vec1.pop_back(); vec2.clear(); for(int i = n - 1; i >= 0; i--) { if(used[i]) { used[i] = 0; break; } } diff = a[n - 1] - a[n - 2]; vec2.push_back(a[n - 1]); it1 = n - 1; while(vec1.size() + vec2.size() < n) { int j = lower(0, it1 - 1, vec2.back() - diff); if(j == it1 || a[j] != vec2.back() - diff) { break; } if(used[j]) { if(vec1.back() != a[j]) { break; } vec1.pop_back(); } it1 = j; vec2.push_back(a[j]); } sort(vec2.begin(), vec2.end()); if(vec1.size() + vec2.size() == n && vec1.size() != 0) { cout << vec1.size() << "\n"; for(int i = 0; i < vec1.size(); i++) { cout << vec1[i] << " "; } cout << "\n"; cout << vec2.size() << "\n"; for(int i = 0; i < vec2.size(); i++) { cout << vec2[i] << " "; } exit(0); } } void funct2() { if(n < 3) { return; } int diff = a[2] - a[0]; vector <int> vec1; used[0] = 1; vec1.push_back(a[0]); int it1 = 1; for(int j = 1; j < n; j++) { if(it1 == n) { break; } int it = lower(it1, a.size() - 1, vec1.back() + diff); if(it != a.size() && a[it] == vec1.back() + diff) { vec1.push_back(a[it]); used[it] = 1; it1 = it + 1; } else { break; } } vector <int> vec2; for(int i = 0; i < n; i++) { if(!used[i]) { vec2.push_back(a[i]); } } bool flag = true; for(int j = 1; j + 1 < vec2.size(); j++) { if(vec2[j] - vec2[j - 1] != vec2[j + 1] - vec2[j]) { flag = false; } } if(flag && vec2.size() > 0) { cout << vec1.size() << "\n"; for(int i = 0; i < vec1.size(); i++) { cout << vec1[i] << " "; } cout << "\n"; cout << vec2.size() << "\n"; for(int i = 0; i < vec2.size(); i++) { cout << vec2[i] << " "; } exit(0); } for(int i = n - 1; i >= 0; i--) { if(used[i]) { used[i] = 0; break; } } vec1.pop_back(); if(vec1.size() == 0) { return; } vec2.clear(); for(int i = 0; i < n; i++) { if(!used[i]) { vec2.push_back(a[i]); } } flag = true; for(int j = 1; j + 1 < vec2.size(); j++) { if(vec2[j] - vec2[j - 1] != vec2[j + 1] - vec2[j]) { flag = false; } } if(flag) { cout << vec1.size() << "\n"; for(int i = 0; i < vec1.size(); i++) { cout << vec1[i] << " "; } cout << "\n"; cout << vec2.size() << "\n"; for(int i = 0; i < vec2.size(); i++) { cout << vec2[i] << " "; } exit(0); } if(vec1.size() == 1) { return; } vec1.pop_back(); vec2.clear(); for(int i = n - 1; i >= 0; i--) { if(used[i]) { used[i] = 0; break; } } diff = a[n - 1] - a[n - 2]; vec2.push_back(a[n - 1]); it1 = n - 1; while(vec1.size() + vec2.size() < n) { int j = lower(0, it1 - 1, vec2.back() - diff); if(j == it1 || a[j] != vec2.back() - diff) { break; } if(used[j]) { if(vec1.back() != a[j]) { break; } vec1.pop_back(); } it1 = j; vec2.push_back(a[j]); } sort(vec2.begin(), vec2.end()); if(vec1.size() + vec2.size() == n && vec1.size() != 0) { cout << vec1.size() << "\n"; for(int i = 0; i < vec1.size(); i++) { cout << vec1[i] << " "; } cout << "\n"; cout << vec2.size() << "\n"; for(int i = 0; i < vec2.size(); i++) { cout << vec2[i] << " "; } exit(0); } } void funct3() { if(n < 3) { return; } int diff = a[2] - a[1]; vector <int> vec1; used[0] = 1; vec1.push_back(a[1]); int it1 = 2; for(int j = 1; j < n; j++) { if(it1 == n) { break; } int it = lower(it1, a.size() - 1, vec1.back() + diff); if(it != a.size() && a[it] == vec1.back() + diff) { vec1.push_back(a[it]); used[it] = 1; it1 = it + 1; } else { return; } } vector <int> vec2; for(int j = 0; j < n; j++) { if(!used[j]) { vec2.push_back(a[j]); } } bool flag = true; for(int j = 1; j + 1 < vec2.size(); j++) { if(vec2[j] - vec2[j - 1] != vec2[j + 1] - vec2[j]) { flag = false; } } if(flag && vec2.size() > 0) { cout << vec1.size() << "\n"; for(int i = 0; i < vec1.size(); i++) { cout << vec1[i] << " "; } cout << "\n"; cout << vec2.size() << "\n"; for(int i = 0; i < vec2.size(); i++) { cout << vec2[i] << " "; } exit(0); } for(int i = n - 1; i >= 0; i--) { if(used[i]) { used[i] = 0; break; } } vec1.pop_back(); if(vec1.size() == 0) { return; } vec2.clear(); for(int i = 0; i < n; i++) { if(!used[i]) { vec2.push_back(a[i]); } } flag = true; for(int j = 1; j + 1 < vec2.size(); j++) { if(vec2[j] - vec2[j - 1] != vec2[j + 1] - vec2[j]) { flag = false; } } if(flag) { cout << vec1.size() << "\n"; for(int i = 0; i < vec1.size(); i++) { cout << vec1[i] << " "; } cout << "\n"; cout << vec2.size() << "\n"; for(int i = 0; i < vec2.size(); i++) { cout << vec2[i] << " "; } exit(0); } if(vec1.size() == 1) { return; } vec1.pop_back(); vec2.clear(); for(int i = n - 1; i >= 0; i--) { if(used[i]) { used[i] = 0; break; } } diff = a[n - 1] - a[n - 2]; vec2.push_back(a[n - 1]); it1 = n - 1; while(vec1.size() + vec2.size() < n) { int j = lower(0, it1 - 1, vec2.back() - diff); if(j == it1 || a[j] != vec2.back() - diff) { break; } if(used[j]) { if(vec1.back() != a[j]) { break; } vec1.pop_back(); } it1 = j; vec2.push_back(a[j]); } sort(vec2.begin(), vec2.end()); if(vec1.size() + vec2.size() == n && vec1.size() != 0) { cout << vec1.size() << "\n"; for(int i = 0; i < vec1.size(); i++) { cout << vec1[i] << " "; } cout << "\n"; cout << vec2.size() << "\n"; for(int i = 0; i < vec2.size(); i++) { cout << vec2[i] << " "; } exit(0); } } signed main(){ // ios_base::sync_with_stdio(false); // cin.tie(NULL); // cout.tie(NULL); cin >> n; a.resize(n); used.resize(n); for(int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); funct1(); for(int i = 0; i < n; i++) { used[i] = 0; } funct2(); for(int i = 0; i < n; i++) { used[i] = 0; } funct3(); cout << -1; return 0; }

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

drvca.cpp: In function 'long long int lower(long long int, long long int, long long int)':
drvca.cpp:15:38: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   if(a[midd] < val || a[midd] == val && used[midd])
drvca.cpp: In function 'void funct1()':
drvca.cpp:48:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(it != a.size() && a[it] == vec1.back() + diff)
      ~~~^~~~~~~~~~~
drvca.cpp:68:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j = 1; j + 1 < vec2.size(); j++)
                 ~~~~~~^~~~~~~~~~~~~
drvca.cpp:78:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < vec1.size(); i++)
                  ~~^~~~~~~~~~~~~
drvca.cpp:84:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < vec2.size(); i++)
                  ~~^~~~~~~~~~~~~
drvca.cpp:112:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j = 1; j + 1 < vec2.size(); j++)
                 ~~~~~~^~~~~~~~~~~~~
drvca.cpp:122:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < vec1.size(); i++)
                  ~~^~~~~~~~~~~~~
drvca.cpp:128:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < vec2.size(); i++)
                  ~~^~~~~~~~~~~~~
drvca.cpp:151:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(vec1.size() + vec2.size() < n)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
drvca.cpp:170:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(vec1.size() + vec2.size() == n && vec1.size() != 0)
     ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
drvca.cpp:173:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < vec1.size(); i++)
                  ~~^~~~~~~~~~~~~
drvca.cpp:179:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < vec2.size(); i++)
                  ~~^~~~~~~~~~~~~
drvca.cpp: In function 'void funct2()':
drvca.cpp:204:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(it != a.size() && a[it] == vec1.back() + diff)
      ~~~^~~~~~~~~~~
drvca.cpp:224:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j = 1; j + 1 < vec2.size(); j++)
                 ~~~~~~^~~~~~~~~~~~~
drvca.cpp:234:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < vec1.size(); i++)
                  ~~^~~~~~~~~~~~~
drvca.cpp:240:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < vec2.size(); i++)
                  ~~^~~~~~~~~~~~~
drvca.cpp:268:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j = 1; j + 1 < vec2.size(); j++)
                 ~~~~~~^~~~~~~~~~~~~
drvca.cpp:278:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < vec1.size(); i++)
                  ~~^~~~~~~~~~~~~
drvca.cpp:284:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < vec2.size(); i++)
                  ~~^~~~~~~~~~~~~
drvca.cpp:307:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(vec1.size() + vec2.size() < n)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
drvca.cpp:326:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(vec1.size() + vec2.size() == n && vec1.size() != 0)
     ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
drvca.cpp:329:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < vec1.size(); i++)
                  ~~^~~~~~~~~~~~~
drvca.cpp:335:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < vec2.size(); i++)
                  ~~^~~~~~~~~~~~~
drvca.cpp: In function 'void funct3()':
drvca.cpp:360:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(it != a.size() && a[it] == vec1.back() + diff)
      ~~~^~~~~~~~~~~
drvca.cpp:380:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j = 1; j + 1 < vec2.size(); j++)
                 ~~~~~~^~~~~~~~~~~~~
drvca.cpp:390:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < vec1.size(); i++)
                  ~~^~~~~~~~~~~~~
drvca.cpp:396:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < vec2.size(); i++)
                  ~~^~~~~~~~~~~~~
drvca.cpp:424:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j = 1; j + 1 < vec2.size(); j++)
                 ~~~~~~^~~~~~~~~~~~~
drvca.cpp:434:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < vec1.size(); i++)
                  ~~^~~~~~~~~~~~~
drvca.cpp:440:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < vec2.size(); i++)
                  ~~^~~~~~~~~~~~~
drvca.cpp:463:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(vec1.size() + vec2.size() < n)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
drvca.cpp:482:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(vec1.size() + vec2.size() == n && vec1.size() != 0)
     ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
drvca.cpp:485:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < vec1.size(); i++)
                  ~~^~~~~~~~~~~~~
drvca.cpp:491:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < vec2.size(); 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...