이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n;
vector <bool> used;
vector <int> a;
void funct1()
{
int diff = a[1] - a[0];
vector <int> vec1;
used[0] = 1;
vec1.push_back(a[0]);
for(int j = 1; j < n; j++)
{
int it = lower_bound(a.begin(), a.end(), vec1.back() + diff) - a.begin();
if(it != a.size() && a[it] == vec1.back() + diff)
{
vec1.push_back(a[it]);
used[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]);
while(vec1.size() + vec2.size() < n)
{
int j = lower_bound(a.begin(), a.end(), vec2.back() - diff) - a.begin();
if(j == a.size() || a[j] != vec2.back() - diff)
{
break;
}
if(used[j])
{
if(vec1.back() != a[j])
{
break;
}
vec1.pop_back();
}
vec2.push_back(a[j]);
}
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()
{
int diff = a[2] - a[0];
vector <int> vec1;
used[0] = 1;
vec1.push_back(a[0]);
for(int j = 1; j < n; j++)
{
int it = lower_bound(a.begin(), a.end(), vec1.back() + diff) - a.begin();
if(it != a.size() && a[it] == vec1.back() + diff)
{
vec1.push_back(a[it]);
used[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]);
while(vec1.size() + vec2.size() < n)
{
int j = lower_bound(a.begin(), a.end(), vec2.back() - diff) - a.begin();
if(j == a.size() || a[j] != vec2.back() - diff)
{
break;
}
if(used[j])
{
if(vec1.back() != a[j])
{
break;
}
vec1.pop_back();
}
vec2.push_back(a[j]);
}
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()
{
int diff = a[2] - a[1];
vector <int> vec1;
used[0] = 1;
vec1.push_back(a[1]);
for(int j = 1; j < n; j++)
{
int it = lower_bound(a.begin(), a.end(), vec1.back() + diff) - a.begin();
if(it != a.size() && a[it] == vec1.back() + diff)
{
vec1.push_back(a[it]);
used[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]);
while(vec1.size() + vec2.size() < n)
{
int j = lower_bound(a.begin(), a.end(), vec2.back() - diff) - a.begin();
if(j == a.size() || a[j] != vec2.back() - diff)
{
break;
}
if(used[j])
{
if(vec1.back() != a[j])
{
break;
}
vec1.pop_back();
}
vec2.push_back(a[j]);
}
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 'void funct1()':
drvca.cpp:16:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(it != a.size() && a[it] == vec1.back() + diff)
~~~^~~~~~~~~~~
drvca.cpp:35:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 1; j + 1 < vec2.size(); j++)
~~~~~~^~~~~~~~~~~~~
drvca.cpp:45:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < vec1.size(); i++)
~~^~~~~~~~~~~~~
drvca.cpp:51:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < vec2.size(); i++)
~~^~~~~~~~~~~~~
drvca.cpp:79:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 1; j + 1 < vec2.size(); j++)
~~~~~~^~~~~~~~~~~~~
drvca.cpp:89:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < vec1.size(); i++)
~~^~~~~~~~~~~~~
drvca.cpp:95:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < vec2.size(); i++)
~~^~~~~~~~~~~~~
drvca.cpp:117:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(vec1.size() + vec2.size() < n)
~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
drvca.cpp:120:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(j == a.size() || a[j] != vec2.back() - diff)
~~^~~~~~~~~~~
drvca.cpp:134:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(vec1.size() + vec2.size() == n && vec1.size() != 0)
~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
drvca.cpp:137:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < vec1.size(); i++)
~~^~~~~~~~~~~~~
drvca.cpp:143: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:159:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(it != a.size() && a[it] == vec1.back() + diff)
~~~^~~~~~~~~~~
drvca.cpp:178:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 1; j + 1 < vec2.size(); j++)
~~~~~~^~~~~~~~~~~~~
drvca.cpp:188:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < vec1.size(); i++)
~~^~~~~~~~~~~~~
drvca.cpp:194:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < vec2.size(); i++)
~~^~~~~~~~~~~~~
drvca.cpp:222:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 1; j + 1 < vec2.size(); j++)
~~~~~~^~~~~~~~~~~~~
drvca.cpp:232:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < vec1.size(); i++)
~~^~~~~~~~~~~~~
drvca.cpp:238:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < vec2.size(); i++)
~~^~~~~~~~~~~~~
drvca.cpp:260:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(vec1.size() + vec2.size() < n)
~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
drvca.cpp:263:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(j == a.size() || a[j] != vec2.back() - diff)
~~^~~~~~~~~~~
drvca.cpp:277:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(vec1.size() + vec2.size() == n && vec1.size() != 0)
~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
drvca.cpp:280:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < vec1.size(); i++)
~~^~~~~~~~~~~~~
drvca.cpp:286: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:302:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(it != a.size() && a[it] == vec1.back() + diff)
~~~^~~~~~~~~~~
drvca.cpp:321:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 1; j + 1 < vec2.size(); j++)
~~~~~~^~~~~~~~~~~~~
drvca.cpp:331:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < vec1.size(); i++)
~~^~~~~~~~~~~~~
drvca.cpp:337:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < vec2.size(); i++)
~~^~~~~~~~~~~~~
drvca.cpp:365:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 1; j + 1 < vec2.size(); j++)
~~~~~~^~~~~~~~~~~~~
drvca.cpp:375:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < vec1.size(); i++)
~~^~~~~~~~~~~~~
drvca.cpp:381:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < vec2.size(); i++)
~~^~~~~~~~~~~~~
drvca.cpp:403:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(vec1.size() + vec2.size() < n)
~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
drvca.cpp:406:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(j == a.size() || a[j] != vec2.back() - diff)
~~^~~~~~~~~~~
drvca.cpp:420:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(vec1.size() + vec2.size() == n && vec1.size() != 0)
~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
drvca.cpp:423:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < vec1.size(); i++)
~~^~~~~~~~~~~~~
drvca.cpp:429:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < vec2.size(); i++)
~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |