QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#612726 | #9412. Stop the Castle | wlh | AC ✓ | 2ms | 3864kb | C++17 | 5.4kb | 2024-10-05 12:42:55 | 2024-10-05 12:42:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ios ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define int long long
typedef pair<int,int> pr;
#define pb(x) push_back(x)
#define all(a) a.begin(),a.end()
#define fi first
#define se second
const int N = 1e6+10;
string YES="YES",Yes="Yes",yes="yes",NO="NO",No="No",no="no";
const int mod=998244353,inf=1e15;
int dx[]={0,0,-1,0,1},dy[]={0,-1,0,1,0};
struct nb{
int x, y;
};
void shuchu(nb w){
cout << w.x << ' ' << w.y << ' ';
}
void solve()
{
int n, m;
cin >> n;
vector<nb>a(n + 1);
map<int, vector<pr>> X, Y;
for(int i = 1; i <= n; i ++){
cin >> a[i].x >> a[i].y;
X[a[i].x].push_back({a[i].y, 1});
Y[a[i].y].push_back({a[i].x, 1});
}
cin >> m;
vector<nb>b(m + 1), bx, by;
for(int i = 1; i <= m; i ++){
cin >> b[i].x >> b[i].y;
X[b[i].x].push_back({b[i].y, 0});
Y[b[i].y].push_back({b[i].x, 0});
}
for(int i = 1; i <= n; i ++) b.push_back(a[i]);
vector<array<nb, 2>>vx, vy;
vector<nb>ans;
// for (auto& [x, vec] : X) {
// sort(vec.begin(), vec.end());
// for (int j = 1; j < vec.size(); ++j) {
// auto& [y1, op1] = vec[j - 1];
// auto& [y2, op2] = vec[j];
// if (op1 && op2) {
// if (y1 + 1 == y2){
// cout << -1 << endl;
// return ;
// }
// vx.push_back({(nb){x, y1}, (nb){x, y2}});
// }
// }
// }
// for (auto& [y, vec] : Y) {
// sort(vec.begin(), vec.end());
// for (int j = 1; j < vec.size(); ++j) {
// auto& [x1, op1] = vec[j - 1];
// auto& [x2, op2] = vec[j];
// if (op1 && op2) {
// if (x1 + 1 == x2){
// cout << -1 << endl;
// return ;
// }
// vy.push_back({(nb){x1, y}, (nb){x2, y}});
// }
// }
// }
for(int i = 1; i <= n; i ++){
for(int j = i + 1; j <= n; j ++){
if(a[i].x == a[j].x){
int f = 1;
for(int k = 1; k <= n + m; k ++) if(b[k].x == a[i].x && min(a[i].y, a[j].y) < b[k].y && b[k].y < max(a[i].y, a[j].y)){
f = 0; break;
}
if(f == 0) continue;
if(a[i].y + 1 == a[j].y || a[j].y + 1 == a[i].y){
cout << -1 << endl;
return ;
}
if(a[i].y < a[j].y) vx.push_back({a[i], a[j]});
else vx.push_back({a[j], a[i]});
}
else if(a[i].y == a[j].y){
int f = 1;
for(int k = 1; k <= n + m; k ++) if(b[k].y == a[i].y && min(a[i].x, a[j].x) < b[k].x && b[k].x < max(a[i].x, a[j].x)){
f = 0; break;
}
if(f == 0) continue;
if(a[i].x + 1 == a[j].x || a[j].x + 1 == a[i].x){
cout << -1 << endl;
return ;
}
if(a[i].x < a[j].x) vy.push_back({a[i], a[j]});
else vy.push_back({a[j], a[i]});
}
}
}
// for(auto [x, y] : vx){
// shuchu(x), shuchu(y);
// cout << endl;
// }
// cout << endl;
// for(auto [x, y] : vy){
// shuchu(x), shuchu(y);
// cout << endl;
// }
int nx = vx.size(), ny = vy.size();
vector<vector<int>> vt(nx + 1);
for(int i = 0; i < nx ; i ++){
auto [x1, x2] = vx[i];
for(int j = 0; j < ny; j ++){
auto [y1, y2] = vy[j];
if(y1.x < x1.x && x1.x < y2.x && x1.y < y1.y && y1.y < x2.y){
// cout << i << ' ' << j << endl;
// shuchu(x1), shuchu(x2);
// shuchu(y1), shuchu(y2);
// cout << endl;
vt[i].push_back(j);
}
}
}
// for(int i = 0 ; i < nx; i ++){
// cout << i << " : " ;
// for(auto x : vt[i]) cout << x << ' ';
// cout << endl;
// }
// cout << endl;
vector<int>vis(ny + 1), match(ny + 1, -1);
auto dfs = [&](auto&& dfs, int u) -> int{
for(auto v:vt[u]){
if(!vis[v]){
vis[v] = 1;
if(match[v] == -1 || dfs(dfs, match[v])){
match[v] = u;
return 1;
}
}
}
return 0;
};
for(int i = 0; i < nx; i ++){
for(int j = 0; j < ny; j ++) vis[j] = 0;
dfs(dfs, i);
}
// for(int j = 0; j < ny; j ++) cout << match[j] << ' ';
// cout << endl;
vector<int>visx(nx);
for(int v = 0; v < ny; v ++){
auto [y1, y2] = vy[v];
if(match[v] != -1){
int u = match[v];
auto [x1, x2] = vx[u];
ans.push_back({x1.x, y1.y});
visx[u] = 1;
}
else{
ans.push_back({(y1.x + y2.x) / 2, y1.y});
}
}
for(int i = 0; i < nx; i ++){
if(!visx[i]){
auto [x1, x2] = vx[i];
ans.push_back({x1.x, (x1.y + x2.y) / 2});
}
}
cout << ans.size() << endl;
for(auto [x, y] : ans){
cout << x << ' ' << y << endl;
}
}
signed main()
{
ios;
int t=1;
cin>>t;
while(t--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3524kb
input:
4 7 1 3 6 6 4 7 2 1 6 3 4 1 2 6 3 3 4 6 4 3 1 2 1 1 2 2 0 3 1 1 1 3 3 3 1 1 2 3 1 1 1 3 2 3 0
output:
2 2 3 4 6 0 1 2 3 -1
result:
ok ok 4 cases (4 test cases)
Test #2:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
21 11 3 5 18 6 19 12 27 48 28 38 30 12 33 18 42 18 43 38 45 46 48 34 3 2 6 24 4 41 45 15 11 6 15 27 16 9 16 14 16 48 19 26 25 12 27 26 28 4 31 40 32 6 33 50 37 50 46 11 50 29 17 1 49 4 9 9 15 9 22 11 31 11 46 14 28 17 5 17 49 18 43 20 31 30 46 33 11 33 33 34 15 36 6 47 10 2 16 46 36 30 11 7 34 7 41 ...
output:
3 24 12 35 38 37 18 5 21 6 23 26 35 50 16 11 16 31 0 1 29 10 0 1 43 28 5 42 44 1 7 1 26 33 28 44 45 0 5 9 1 26 15 27 41 29 33 44 21 1 32 10 0 0 0 0 6 23 10 29 46 35 34 12 25 23 44 29 27 0 3 32 17 20 30 43 28 0 -1 3 16 36 24 39 25 9 6 5 5 8 9 6 10 6 11 6 5 7 5
result:
ok ok 21 cases (21 test cases)
Test #3:
score: 0
Accepted
time: 1ms
memory: 3664kb
input:
2 200 7 52 9 160 10 4 12 61 18 436 19 430 20 499 24 139 25 416 29 53 33 153 35 275 35 310 37 25 38 477 39 349 42 120 44 158 45 330 49 486 50 204 51 67 52 138 52 305 56 139 63 132 66 4 67 327 70 484 71 67 72 308 74 218 76 479 81 139 82 90 86 201 87 335 91 35 91 220 92 496 94 29 94 436 96 359 97 299 1...
output:
46 132 160 38 4 224 61 56 436 67 499 52 139 126 153 126 275 90 25 93 477 61 67 154 138 270 305 68 139 91 67 94 35 154 496 306 374 187 467 139 429 185 147 199 432 277 356 295 35 274 186 393 112 283 272 352 186 295 367 311 177 334 367 349 61 398 385 400 307 417 305 35 292 187 442 224 412 260 258 261 4...
result:
ok ok 2 cases (2 test cases)
Test #4:
score: 0
Accepted
time: 1ms
memory: 3856kb
input:
20 13 89287395 441913071 89287395 590314987 142917372 582720391 142917372 598813561 232930851 582720391 263974835 468188689 263974835 490702144 543529670 152471388 543529670 219371706 647691663 598813561 772865038 598813561 773363571 482933265 773363571 561453301 8 128947560 120560639 264980960 4742...
output:
8 187924111 582720391 395304517 598813561 710278350 598813561 89287395 516114029 142917372 590766976 263974835 479445416 543529670 185921547 773363571 522193283 7 131614064 871951216 138082116 358274214 808969359 818037531 639043654 762966373 839408368 354711322 808969359 574744809 808969359 9041269...
result:
ok ok 20 cases (20 test cases)
Test #5:
score: 0
Accepted
time: 1ms
memory: 3628kb
input:
2 184 35763790 435860426 152681166 443483111 261932524 745277126 261932524 787982418 314305867 342102981 314305867 522593781 314305867 747023891 314305867 811404535 314305867 816914009 314305867 857896659 319901983 797458033 321347896 342102981 332550928 902179526 343207116 914408792 350635050 15515...
output:
160 350635050 435860426 314305867 443483111 314305867 787982418 317826881 342102981 350635050 747023891 407380694 811404535 469496529 816914009 332470458 857896659 350635050 797458033 335991473 342102981 359445708 902179526 561219907 914408792 356189972 342102981 469496529 526518374 496813081 787982...
result:
ok ok 2 cases (2 test cases)
Test #6:
score: 0
Accepted
time: 1ms
memory: 3640kb
input:
2 193 78368109 329329995 87932514 657474465 87932514 903492853 94608574 845872655 103602204 88649154 124431127 405860533 145262472 108198774 145262472 907127202 154400439 136367504 165270984 773451933 184157521 409828915 197728547 291882089 197728547 609623645 211750768 843867422 246178069 108396139...
output:
145 365329221 329329995 145262472 903492853 365329221 845872655 234465712 88649154 365329221 405860533 365329221 136367504 365329221 773451933 197728547 409828915 246178069 291882089 391226954 843867422 365329221 909607734 291242118 564718673 328285669 211732513 365329221 211655411 416747507 8453631...
result:
ok ok 2 cases (2 test cases)
Test #7:
score: 0
Accepted
time: 1ms
memory: 3704kb
input:
2 192 1075648 579875717 1075648 937648715 1393060 191616432 3957616 541362608 3957616 971879257 5415801 541362608 5887448 541362608 5887448 624842533 25767120 610618164 26193206 214214028 26193206 231445627 26727662 374314271 29550509 755417826 29550509 917592925 30033126 610618164 31134588 58188305...
output:
131 31134588 191616432 4686708 541362608 5651624 541362608 31134588 541362608 223207847 624842533 27900123 610618164 33207011 231445627 223207847 374314271 30342548 755417826 622701955 58188305 746663436 194741814 31742355 755417826 46425938 755417826 85850243 231445627 341366249 934726175 223207847...
result:
ok ok 2 cases (2 test cases)
Test #8:
score: 0
Accepted
time: 1ms
memory: 3628kb
input:
20 14 378192988 147499872 378192988 837331700 449924898 147499872 449924898 837331700 592684636 147499872 592684636 837331700 783332532 147499872 783332532 837331700 378192988 197547597 783332532 197547597 378192988 343857831 783332532 343857831 378192988 576579017 783332532 576579017 2 449924898 19...
output:
15 414058943 147499872 414058943 837331700 521304767 147499872 521304767 837331700 688008584 147499872 688008584 837331700 580762760 576579017 378192988 172523734 378192988 706955358 783332532 172523734 783332532 706955358 378192988 270702714 783332532 270702714 378192988 460218424 783332532 4602184...
result:
ok ok 20 cases (20 test cases)
Test #9:
score: 0
Accepted
time: 1ms
memory: 3636kb
input:
2 200 8623893 3649468 8623893 989134714 24820918 3649468 24820918 989134714 43705451 3649468 43705451 989134714 45500146 3649468 45500146 989134714 58265855 3649468 58265855 989134714 112263159 3649468 112263159 989134714 126496650 3649468 126496650 989134714 137574156 3649468 137574156 989134714 14...
output:
249 16722405 3649468 16722405 989134714 34263184 3649468 34263184 989134714 44602798 3649468 44602798 989134714 51883000 3649468 51883000 989134714 85264507 3649468 85264507 989134714 119379904 3649468 119379904 989134714 132035403 3649468 132035403 989134714 138831800 3649468 138831800 989134714 14...
result:
ok ok 2 cases (2 test cases)
Test #10:
score: 0
Accepted
time: 1ms
memory: 3864kb
input:
2 200 2691939 27674656 2691939 984614319 30225807 27674656 30225807 984614319 39388076 27674656 39388076 984614319 55883389 27674656 55883389 984614319 77258752 27674656 77258752 984614319 106874917 27674656 106874917 984614319 144383292 27674656 144383292 984614319 145360776 27674656 145360776 9846...
output:
216 16458873 27674656 16458873 984614319 34806941 27674656 34806941 984614319 47635732 27674656 47635732 984614319 66571070 27674656 66571070 984614319 92066834 27674656 92066834 984614319 125629104 27674656 125629104 984614319 144872034 27674656 144872034 984614319 147676653 27674656 147676653 9846...
result:
ok ok 2 cases (2 test cases)
Test #11:
score: 0
Accepted
time: 2ms
memory: 3664kb
input:
2 200 1005937 7 3412691 7 5764908 7 7897785 7 8061992 7 12801501 7 18529696 7 22574605 7 25203351 7 34574958 7 34998216 7 40928451 7 49792193 7 55962320 7 59632864 7 62353373 7 62611196 7 65346591 7 71459320 7 71550121 7 72215989 7 82584263 7 86119549 7 96204862 7 96940713 7 97693112 7 102067050 7 1...
output:
199 2209314 7 4588799 7 6831346 7 7979888 7 10431746 7 15665598 7 20552150 7 23888978 7 29889154 7 34786587 7 37963333 7 45360322 7 52877256 7 57797592 7 60993118 7 62482284 7 63978893 7 68402955 7 71504720 7 71883055 7 77400126 7 84351906 7 91162205 7 96572787 7 97316912 7 99880081 7 103760846 7 10...
result:
ok ok 2 cases (2 test cases)
Extra Test:
score: 0
Extra Test Passed