이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
int main() {
int n, ans;
vector<int> p;
cin >> n;
p.resize(n+1);
for(int i=1; i<=n; i++) {
cin >> p[i];
}
vector<int>small,big,v;
for(int i=1; i<=n; i++) v.push_back(i);
if(n <= 6) {
cout << "query ";
for(int i=0; i<v.size(); i++) {
cout << v[i] << " ";
}
cout << endl;
cin >> ans;
if(ans==1) {
if(small.empty()) {
small = v;
} else {
small = min(small, v);
}
if(big.empty()) {
big = v;
} else {
big = max(big, v);
}
}
while(next_permutation(v.begin(), v.end())) {
cout << "query ";
for(int i=0; i<v.size(); i++) {
cout << v[i] << " ";
}
cout << endl;
cin >> ans;
if(ans==1) {
if(small.empty()) {
small = v;
} else {
small = min(small, v);
}
if(big.empty()) {
big = v;
} else {
big = max(big, v);
}
}
}
cout << "end" << endl;
for(int i=0; i<small.size(); i++) cout << small[i] << " ";
cout << endl;
for(int i=0; i<big.size(); i++) cout << big[i] << " ";
cout << endl;
return 0;
}
pair<int,int>pil;
pil.fi = -1;
pil.se = -1;
int ag[1001];
int id;
for(int i=2; i<=n-2; i++) {
cout << "query ";
swap(p[i], p[i+1]);
for(int j=1; j<=n; j++) {
cout << p[j] << " ";
}
cout << endl;
cin >> ans;
if(ans==0) {
swap(p[i], p[i+1]);
cout << "query ";
id = i-1;
if(id-1 >= 1) {
swap(p[id], p[id-1]);
for(int j=1; j<=n; j++) {
cout << p[j] << " ";
}
cout << endl;
cin >> ans;
if(ans==1) {
swap(p[id], p[id-1]);
pil.fi = p[id+2];
pil.se = p[id+3];
p.erase(p.begin()+id+2, p.begin()+id+4);
//for (auto it:p) cout << it << " ";
} else {
swap(p[id], p[id-1]);
pil.fi = p[id];
pil.se = p[id+1];
p.erase(p.begin()+id, p.begin()+id+2);
//for (auto it:p) cout << it << " ";
}
} else
if(id+4 <= n) {
swap(p[id+3], p[id+4]);
for(int j=1; j<=n; j++) {
cout << p[j] << " ";
}
cout << endl;
cin >> ans;
if(ans==1) {
swap(p[id+3], p[id+4]);
pil.fi = p[id];
pil.se = p[id+1];
p.erase(p.begin()+id, p.begin()+id+2);
//for (auto it:p) cout << it << " ";
} else {
swap(p[id+3], p[id+4]);
pil.fi = p[id+2];
pil.se = p[id+3];
p.erase(p.begin()+id+2, p.begin()+id+4);
//for (auto it:p) cout << it << " ";
}
}
break;
}
swap(p[i], p[i+1]);
}
for(int i=1; i<=id; i++) {
if(ag[i] == 0) {
}
}
sort(p.begin(), p.end());
//debug
//cout << "pas " << pil.fi << " " << pil.se << endl;
int mins = min(pil.fi, pil.se);
int maks = max(pil.fi, pil.se);
if(mins < p[1] || maks > p[p.size()-1]) {
cout << "end" << endl;
if(mins < p[1]) {
cout << mins << " " << maks << " ";
}
for(int i=1; i<=p.size()-1; i++) {
cout << p[i] << " ";
}
if(mins > p[1]) {
cout << mins << " " << maks;
}
cout << endl;
if(maks > p[p.size()-1]) {
cout << maks << " " << mins << " ";
}
for(int i=p.size()-1; i>=1; i--) {
cout << p[i] << " ";
}
if(maks < p[p.size()-1]) {
cout << maks << " " << mins << " ";
}
cout << endl;
return 0;
}
for(int i=1; i<=n; i++) {
if(p[i]==mins-1) {
p.insert(p.begin()+i+1, {mins, maks});
break;
}
}
//for (auto it:p) cout << it << " ";
cout << "end" << endl;
for(int i=1; i<=n; i++) {
cout << p[i] << " ";
}
cout << endl;
for(int i=n; i>=1; i--) {
cout << p[i] << " ";
}
cout << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
zagonetka.cpp: In function 'int main()':
zagonetka.cpp:19:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for(int i=0; i<v.size(); i++) {
| ~^~~~~~~~~
zagonetka.cpp:38:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i=0; i<v.size(); i++) {
| ~^~~~~~~~~
zagonetka.cpp:57:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int i=0; i<small.size(); i++) cout << small[i] << " ";
| ~^~~~~~~~~~~~~
zagonetka.cpp:59:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(int i=0; i<big.size(); i++) cout << big[i] << " ";
| ~^~~~~~~~~~~
zagonetka.cpp:140:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
140 | for(int i=1; i<=p.size()-1; 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... |