QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#296015 | #4831. Eager Sorting | hos_lyric | 0 | 1ms | 4080kb | C++14 | 3.1kb | 2024-01-01 22:09:47 | 2024-01-01 22:09:48 |
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
int N;
int ask(int i, int j) {
printf("%d %d\n", i + 1, j + 1);
fflush(stdout);
int ret;
scanf("%d", &ret);
if (ret == -1) {
exit(0);
}
return ret;
}
vector<int> where;
bool cmp(int u, int v) {
if (u == v) return false;
if (where[u] > where[v]) return !cmp(v, u);
const int res = ask(where[u], where[v]);
if (res) {
swap(where[u], where[v]);
}
return !res;
}
vector<int> us;
template <class Iter, class Comp>
void mergeSort(Iter first, Iter last, Iter buffer, Comp comp) {
if (last - first >= 2) {
if (first == us.begin() && last == us.begin() + N/2) {
// check sorted?
bool ok = true;
for (int i = 0; i < N/2 - 1; ++i) {
ok = ok && cmp(us[i], us[i + 1]);
}
cerr<<"skip [0, N/2): "<<ok<<endl;
if (ok) {
return;
}
}
Iter middle = first + (last - first) / 2;
mergeSort(first, middle, buffer, comp);
mergeSort(middle, last, buffer, comp);
Iter i = first, j = first, k = buffer, l = buffer;
for (; j != middle; ) *l++ = std::move(*j++);
for (; k != l && j != last; ) *i++ = comp(*j, *k) ? *j++ : *k++;
for (; k != l; ) *i++ = std::move(*k++);
}
}
template <class T, class Comp> void mergeSort(T *first, T *last, Comp comp) {
vector<T> buffer((last - first) / 2);
mergeSort(first, last, buffer.data(), comp);
}
template <class T, class Comp> void mergeSort(vector<T> &as, Comp comp) {
vector<T> buffer(as.size() / 2);
mergeSort(as.begin(), as.end(), buffer.begin(), comp);
}
int main() {
scanf("%d", &N);
where.resize(N);
us.resize(N);
for (int u = 0; u < N; ++u) {
where[u] = u;
us[u] = u;
}
mergeSort(us, cmp);
for (int i = 0; i < N; ++i) {
const int u = us[i];
if (i != where[u]) {
ask(i, where[u]);
}
}
puts("-1 -1");
fflush(stdout);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4080kb
Interactor to First Run
5 0 1 0 1 0 1 0 1 -1
First Run to Interactor
1 2 4 5 3 4 1 3 3 4 2 4 4 5 2 3 3 2
Interactor to Second Run
5 0 0 0 0 0
Second Run to Interactor
1 2 4 5 3 4 1 3 2 3 -1 -1
Manager to Checker
OK good job!
result:
ok OK
Test #2:
score: 100
Accepted
time: 1ms
memory: 3680kb
Interactor to First Run
1
First Run to Interactor
-1 -1
Interactor to Second Run
1
Second Run to Interactor
-1 -1
Manager to Checker
OK good job!
result:
ok OK
Test #3:
score: 100
Accepted
time: 0ms
memory: 3776kb
Interactor to First Run
2 0
First Run to Interactor
1 2 -1 -1
Interactor to Second Run
2 0
Second Run to Interactor
1 2 -1 -1
Manager to Checker
OK good job!
result:
ok OK
Test #4:
score: 100
Accepted
time: 1ms
memory: 3860kb
Interactor to First Run
2 1
First Run to Interactor
1 2 -1 -1
Interactor to Second Run
2 0
Second Run to Interactor
1 2 -1 -1
Manager to Checker
OK good job!
result:
ok OK
Test #5:
score: 100
Accepted
time: 1ms
memory: 3840kb
Interactor to First Run
9 1 0 0 0 0 1 0 1 1 0 0 1 0 0 0 1 1 1 0 1 0 0 1
First Run to Interactor
1 2 1 2 3 4 1 3 2 3 5 6 8 9 7 8 8 9 5 7 6 7 1 5 5 6 2 6 3 6 4 6 6 7 7 8 8 9 2 5 3 2 4 3 5 4 -1 -1
Interactor to Second Run
9 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
Second Run to Interactor
1 2 2 3 3 4 1 2 3 4 1 3 2 3 5 6 8 9 7 8 5 7 6 7 1 5 2 5 3 5 4 5 -1 -1
Manager to Checker
OK good job!
result:
ok OK
Test #6:
score: 100
Accepted
time: 1ms
memory: 4080kb
Interactor to First Run
9 0 1 0 1 1 1 0 1 1 0 0 1 0 0 0 1 0 1 1 1 0 1 1 0
First Run to Interactor
1 2 2 3 1 3 2 4 1 2 2 4 5 6 8 9 7 8 8 9 5 7 6 7 7 8 1 5 2 5 4 5 5 6 3 6 6 7 7 8 8 9 3 4 4 5 5 3 -1 -1
Interactor to Second Run
9 0 0 0 0 0 0 0 0 0 0 0 0
Second Run to Interactor
1 2 2 3 3 4 5 6 8 9 7 8 5 7 6 7 1 5 2 5 3 5 4 5 -1 -1
Manager to Checker
OK good job!
result:
ok OK
Test #7:
score: 100
Accepted
time: 1ms
memory: 3808kb
Interactor to First Run
6 1 0 0 0 1 0 1 1 0 1 1 1 0 1 0
First Run to Interactor
1 2 1 3 1 2 2 3 5 6 4 5 1 4 4 5 5 6 2 6 2 4 3 5 4 2 5 6 6 3 -1 -1
Interactor to Second Run
6 0 0 0 0 0 0 0
Second Run to Interactor
1 2 2 3 5 6 4 5 1 4 2 4 3 4 -1 -1
Manager to Checker
OK good job!
result:
ok OK
Test #8:
score: 100
Accepted
time: 1ms
memory: 3788kb
Interactor to First Run
20 1 0 0 1 1 1 1 0 1 1 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0 1 1 0 1 1 0 0 1 0 1 1 1 0 0 1 1 0 1 0 0 0 0 0 1 1 0 1 0 0 0 0 1 1 1 1 0 1 0 1 0 0 0 1 1 0 1 0 0 0 0 1 0 0 0 1 0 1 1 1 0
First Run to Interactor
1 2 1 2 4 5 3 4 4 5 1 3 3 4 4 5 2 5 6 7 9 10 8 9 6 8 8 9 7 9 9 10 1 6 3 6 4 6 6 8 7 8 2 8 8 9 5 9 11 12 14 15 13 14 14 15 11 13 13 14 14 15 12 15 16 17 19 20 18 19 19 20 16 18 18 19 17 19 11 16 16 18 17 18 18 19 19 20 13 20 14 20 12 20 15 20 1 11 11 16 16 17 3 17 17 18 4 18 6 18 7 18 2 18 18 19 13 1...
Interactor to Second Run
20 0 0 0 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0
Second Run to Interactor
1 2 2 3 3 4 4 5 1 2 4 5 3 4 1 3 2 3 6 7 9 10 8 9 9 10 6 8 8 9 7 9 1 6 2 6 3 6 4 6 6 8 5 8 11 12 14 15 13 14 11 13 12 13 13 14 16 17 19 20 18 19 16 18 17 18 11 16 12 16 13 16 14 16 15 16 1 11 2 11 3 11 4 11 6 11 5 11 8 11 7 11 9 11 11 12 10 12 12 13 5 6 6 5 7 8 8 7 10 11 11 10 -1 -1
Manager to Checker
OK good job!
result:
ok OK
Test #9:
score: 100
Accepted
time: 1ms
memory: 3788kb
Interactor to First Run
15 0 0 0 1 0 0 0 1 0 1 1 0 1 0 0 1 0 0 0 1 1 1 1 1 1 1 1 0 1 0 0 0 1 1 0 1 1 1 1 1 0 1 1 1 0 1 1 0 0 0 0 0 1 0 1
First Run to Interactor
1 2 2 3 3 4 4 5 2 3 1 2 4 5 6 7 4 6 5 6 6 7 1 4 2 4 4 5 3 5 8 9 10 11 8 10 9 10 12 13 14 15 12 14 14 15 8 12 12 14 14 15 13 15 9 15 10 15 1 8 2 8 4 8 3 8 8 12 12 14 5 14 13 14 6 14 9 14 7 14 10 14 14 15 11 15 3 4 4 3 5 8 6 12 7 5 8 13 9 6 10 9 11 7 12 10 13 14 14 11 -1 -1
Interactor to Second Run
15 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 1 1 0 1
Second Run to Interactor
1 2 2 3 3 4 4 5 5 6 6 7 8 9 10 11 8 10 9 10 10 11 12 13 14 15 12 14 13 14 8 12 9 12 12 13 10 13 11 13 13 14 1 8 2 8 3 8 4 8 5 8 6 8 7 8 8 9 9 12 10 12 11 12 -1 -1
Manager to Checker
OK good job!
result:
ok OK
Test #10:
score: 0
Wrong Answer
time: 1ms
memory: 3812kb
Interactor to First Run
20 0 1 0 1 0 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 0 1 0 0 1 0 1 0 1 1 1 1 1 0 0 1 1 0 0 0 0 0 0 1 1 1 0 1 0 0 1 1 1 0 1 0 0 0 1 0 1 1 0 1 1 1 0 0 0 1 0 0 0 0 1 0 1
First Run to Interactor
1 2 2 3 1 3 4 5 2 4 1 2 2 4 4 5 6 7 9 10 8 9 9 10 6 8 8 9 9 10 1 6 6 8 2 8 8 9 9 10 7 10 4 10 11 12 14 15 13 14 14 15 11 13 12 13 13 14 16 17 19 20 18 19 19 20 16 18 18 19 19 20 11 16 12 16 13 16 16 18 18 19 14 19 15 19 1 11 6 11 2 11 8 11 11 12 12 13 13 16 9 16 16 18 7 18 4 18 14 18 10 18 15 18 18 ...
Interactor to Second Run
20 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 1 1 1 1 0 1 0 0 1 1 1 0 0 1 0 0 1 1 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1 1 0 1 1 0 0 0 1
Second Run to Interactor
1 2 2 3 3 4 1 2 3 5 3 4 4 5 1 3 2 3 6 7 9 10 8 9 6 8 7 8 1 6 2 6 3 6 6 7 4 7 5 7 7 8 8 9 9 10 11 12 14 15 13 14 14 15 11 13 12 13 13 14 14 15 16 17 19 20 18 19 19 20 16 18 17 18 18 19 19 20 11 16 12 16 16 17 13 17 14 17 15 17 17 18 1 11 2 11 3 11 6 11 4 11 5 11 11 12 7 12 8 12 9 12 10 12 12 16 13 16...
Manager to Checker
WA array is not sorted!
result:
wrong answer WA