QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#272750 | #6414. Classical Maximization Problem | ucup-team859# | WA | 103ms | 44420kb | C++14 | 3.1kb | 2023-12-02 19:01:09 | 2023-12-02 19:01:09 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
using ll = long long;
using ull = unsigned long long;
string to_string(const string &s) {
return '"' + s + '"';
}
string to_string(bool b) {
return b ? "true" : "false";
}
template <typename A, typename B>
string to_string(const pair<A, B> &p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename T>
string to_string(const T &v) {
string s = "{";
bool first = true;
for (const auto &it : v) {
if (!first)
s += ", ";
else
first = false;
s += to_string(it);
}
return s += "}";
}
void debug_out() {
cerr << endl;
}
template <typename T, typename... Args>
void debug_out(const T &first, const Args&... rest) {
cerr << to_string(first) << " ";
debug_out(rest...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
auto startTime = high_resolution_clock::now();
int get_time() {
auto stopTime = chrono::high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stopTime - startTime);
return duration.count(); // in ms
}
const int DIM = 2e5 + 5;
vector<pair<int, int>> v[8 * DIM];
int wh[2 * DIM];
bool viz[8 * DIM];
int nr = 0;
void dfs(int nod, int papa = 0) {
nr += v[nod].size();
viz[nod] = 1;
int last = 0, wp = 0;
for (auto it : v[nod]) {
if (it.first == nod) {
wp = it.second;
continue;
}
if (!viz[it.first])
dfs(it.first, nod);
if (!wh[it.second]) {
if (!last)
last = it.second;
else {
wh[it.second] = last;
wh[last] = it.second;
last = 0;
}
}
}
if (last && wp) {
wh[last] = wp;
wh[wp] = last;
}
}
void solve() {
int n;
cin >> n;
vector<int> x(2 * n + 1, 0);
vector<int> y(2 * n + 1, 0);
int n_x = 0, n_y = 0;
map<int, int> fx, fy;
for (int i = 1; i <= 2 * n; ++i) {
cin >> x[i] >> y[i];
if (!fx.count(x[i]))
fx[x[i]] = ++n_x;
if (!fy.count(y[i]))
fy[y[i]] = ++n_y;
}
for (int i = 1; i <= 2 * n; ++i) {
wh[i] = 0;
v[fx[x[i]]].push_back({fy[y[i]] + n_x, i});
v[fy[y[i]] + n_x].push_back({fx[x[i]], i});
}
int ans = 0;
for (int i = 1; i <= n_x; ++i) {
if (!viz[i]) {
nr = 0;
dfs(i);
ans += nr / 4;
}
}
cout << ans << '\n';
vector<int> bads;
for (int i = 1; i <= 2 * n; ++i) {
if (!wh[i])
bads.push_back(i);
else if (i < wh[i]) {
cout << i << " " << wh[i] << '\n';
}
}
while (!bads.empty()) {
int x = bads.back();
bads.pop_back();
cout << x << " ";
x = bads.back();
bads.pop_back();
cout << x << "\n";
}
for (int i = 1; i <= 8 * n; ++i) {
viz[i] = 0;
v[i].clear();
}
}
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 42196kb
input:
3 2 0 0 0 1 1 0 1 1 2 0 0 0 1 0 2 0 3 2 0 0 1 1 2 2 3 3
output:
2 1 3 2 4 2 1 2 3 4 0 4 3 2 1
result:
ok ok (3 test cases)
Test #2:
score: 0
Accepted
time: 99ms
memory: 43884kb
input:
10000 2 -107276936 -310501829 419434212 585811870 -65754386 -491212232 381152038 897148193 3 -474045168 493506332 299114415 540203303 165808153 983551 -506936261 -694189769 766718170 -725540031 975267148 -593051087 1 -818952276 -762387923 584023914 -612401389 6 -77701228 -266484128 659434465 6322062...
output:
0 4 3 2 1 0 6 5 4 3 2 1 0 2 1 0 12 11 10 9 8 7 6 5 4 3 2 1 0 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 2 1 0 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 6 5 4 3...
result:
ok ok (10000 test cases)
Test #3:
score: 0
Accepted
time: 91ms
memory: 42764kb
input:
10000 1 999855386 999580905 999342928 999615227 21 999601032 999015398 999155628 999176944 999309856 999524434 999121011 999509537 999323572 999685730 999272272 999769606 999450559 999390758 999632027 999178534 999024993 999463838 999784856 999374197 999980525 999366771 999241260 999516879 999599548...
output:
0 2 1 0 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 28 27 26 25 2...
result:
ok ok (10000 test cases)
Test #4:
score: 0
Accepted
time: 100ms
memory: 42476kb
input:
10000 5 999984799 999981445 999958394 999984217 999994978 999981258 999955539 999938710 999936554 999963561 999907222 999907508 999938166 999941959 999910567 999986887 999901446 999961092 999994730 999963038 5 999916115 999962400 999948250 999940355 999954204 999920844 999928148 999990369 999978118 ...
output:
0 10 9 8 7 6 5 4 3 2 1 0 10 9 8 7 6 5 4 3 2 1 0 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 8 7 6 5 4 3 2 1 0 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 10 9 8 7 6 5 4 3 2 1 0 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 68 67 66 65 64 63 62 6...
result:
ok ok (10000 test cases)
Test #5:
score: 0
Accepted
time: 103ms
memory: 44420kb
input:
10000 1 999990146 999993828 999995909 999996353 56 999999851 999991179 999997250 999997987 999990590 999997316 999997350 999996856 999997034 999996236 999999396 999996897 999991180 999993309 999991265 999995185 999993952 999994054 999990210 999994471 999993201 999995893 999997170 999998971 999998201...
output:
0 2 1 1 76 111 112 110 109 108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 ...
result:
ok ok (10000 test cases)
Test #6:
score: -100
Wrong Answer
time: 91ms
memory: 44036kb
input:
10000 5 999999432 999999813 999999271 999999233 999999043 999999606 999999523 999999406 999999564 999999274 999999641 999999102 999999903 999999858 999999058 999999098 999999974 999999119 999999643 999999620 5 999999370 999999738 999999181 999999907 999999163 999999783 999999393 999999086 999999661 ...
output:
0 10 9 8 7 6 5 4 3 2 1 0 10 9 8 7 6 5 4 3 2 1 0 6 5 4 3 2 1 0 10 9 8 7 6 5 4 3 2 1 1 9 10 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 8 7 6 5 4 3 2 1 1 12 13 16 15 14 11 10 9 8 7 6 5 4 3 2 1 0 4 3 2 1 0 4 3 2 1 1 10 44 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32...
result:
wrong answer wrong number of friendly pairs: printed 7, but it is actually 6 (test case 2335)