QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#184671 | #5559. Guessing Game | rgnerdplayer | AC ✓ | 86ms | 40308kb | C++20 | 3.1kb | 2023-09-21 02:59:19 | 2023-09-21 02:59:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
struct TwoSat {
int n;
vector<vector<int>> g;
vector<int> ans;
TwoSat(int n) : n(n), g(2 * n), ans(n) {}
void add(int u, bool x) {
g[2 * u + !x].push_back(2 * u + x);
}
void add(int u, bool x, int v, bool y) {
g[2 * u + !x].push_back(2 * v + y);
g[2 * v + !y].push_back(2 * u + x);
}
bool satisfiable() {
vector<int> where(2 * n, -1), dfn(2 * n, -1), low(2 * n, -1), stk;
auto dfs = [&](auto dfs, int u) -> void {
static int T = 0, cnt = 0;
dfn[u] = low[u] = T++;
stk.push_back(u);
for (auto v : g[u]) {
if (dfn[v] == -1) {
dfs(dfs, v);
low[u] = min(low[u], low[v]);
} else if (where[v] == -1) {
low[u] = min(low[u], dfn[v]);
}
}
if (dfn[u] == low[u]) {
int v;
do {
v = stk.back();
where[v] = cnt;
stk.pop_back();
} while (u != v);
cnt++;
}
};
for (int i = 0; i < 2 * n; i++)
if (dfn[i] == -1)
dfs(dfs, i);
for (int i = 0; i < n; i++) {
if (where[2 * i] == where[2 * i + 1]) {
ans.clear();
return false;
}
ans[i] = where[2 * i] > where[2 * i + 1];
}
return true;
}
};
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
auto solve = [&]() {
int n;
cin >> n;
vector<int> c(7);
for (int i = 0; i < 7; i++) {
cin >> c[i];
}
int N = 0;
vector<vector<int>> id(7);
for (int i = 0; i < 7; i++) {
id[i].resize(c[i]);
for (int j = 0; j < c[i]; j++) {
id[i][j] = N++;
}
}
vector a(n, vector<int>(7));
for (int i = 0; i < n; i++) {
for (int j = 0; j < 7; j++) {
cin >> a[i][j];
}
}
vector<int> b(2);
cin >> b[0] >> b[1];
TwoSat ts(N);
auto index = [&](int contest, int day) {
return id[day][abs(contest) - 1];
};
auto flag = [&](int contest) {
return contest > 0;
};
for (int i = 0; i < n; i++) {
for (int x = 0; x < 7; x++) {
for (int y = x + 1; y < 7; y++) {
ts.add(index(a[i][x], x), !flag(a[i][x]), index(a[i][y], y), !flag(a[i][y]));
}
}
}
for (int i = 0; i < 2; i++) {
ts.add(index(b[i], i + 5), flag(b[i]));
}
cout << (ts.satisfiable() ? "possible" : "impossible") << '\n';
};
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
input:
3 4 4 4 4 4 4 4 1 1 1 1 4 -2 1 2 2 2 2 -4 1 -1 3 3 3 3 -3 3 3 -2 -1
output:
impossible
result:
ok single line: 'impossible'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
3 4 4 4 4 4 4 4 4 3 2 1 4 1 1 2 4 4 2 2 4 2 2 3 3 4 1 3 2 -2 -1
output:
possible
result:
ok single line: 'possible'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
4 1 1 1 1 1 1 1 -1 -1 -1 -1 1 1 -1 -1 1 1 1 -1 -1 1 -1 -1 1 -1 -1 -1 1 -1 -1 -1 -1 -1 1 -1 -1 -1
output:
impossible
result:
ok single line: 'impossible'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
10 7 7 7 7 7 7 7 -3 -7 1 -5 1 2 4 5 -7 6 2 4 -7 2 5 -3 6 -3 -6 -2 -5 -7 3 -5 2 -1 -3 7 -4 -2 4 5 7 6 -3 1 1 5 -6 -3 -7 7 7 -5 5 -2 3 1 -7 -5 -2 -3 -4 -5 4 7 2 7 -2 -1 6 1 -7 2 3 3 1 -1 3 3 5 7
output:
impossible
result:
ok single line: 'impossible'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
10 7 7 7 7 7 7 7 4 1 -2 7 6 6 3 -6 5 2 4 -7 -7 3 -1 -4 -5 -3 4 -3 1 -5 -2 -7 7 4 -3 -3 -7 3 -5 -5 -1 4 -5 2 7 7 2 -1 5 -4 -4 -2 -6 5 2 -6 -4 -6 3 -1 3 4 -6 -7 -5 -5 -2 -7 -3 7 7 3 -2 6 -4 -2 6 4 7 -3
output:
impossible
result:
ok single line: 'impossible'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
10 7 7 7 7 7 7 7 -7 -2 2 -2 2 6 -7 -6 -5 -6 4 2 -1 5 -2 5 -4 -6 3 -6 -3 2 1 -7 5 3 1 4 -4 -4 3 -7 3 7 -4 -5 -3 -7 7 7 -6 -1 5 -2 5 -1 -3 1 -7 -3 -2 -2 -1 -1 -6 2 5 7 3 -3 2 3 4 3 6 -5 6 4 2 -2 5 1
output:
impossible
result:
ok single line: 'impossible'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
10 7 7 7 7 7 7 7 7 5 3 2 -6 7 -5 3 -1 1 6 5 -1 6 -6 7 -4 -2 7 4 3 4 -3 1 1 7 -6 6 -6 -1 -4 3 -5 3 2 -4 -6 -6 1 5 -1 3 -2 7 -6 6 -6 -1 -4 -3 4 2 5 5 -5 2 -4 -1 1 -4 -7 3 -5 7 2 7 5 2 -6 6 -7 -6
output:
possible
result:
ok single line: 'possible'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
4 3 3 3 3 3 3 3 1 -2 -1 3 1 2 1 3 -2 2 -1 2 3 1 3 1 3 -2 2 1 1 -2 -1 3 1 1 3 3 -3 -3
output:
possible
result:
ok single line: 'possible'
Test #9:
score: 0
Accepted
time: 2ms
memory: 4432kb
input:
1000 500 20 20 500 500 500 10 -115 -19 7 431 92 -225 10 -158 14 -8 -87 412 -60 8 160 -5 1 -416 -264 -372 -10 404 -9 -6 -438 383 396 8 170 -7 2 4 -285 -149 -4 338 -9 6 -173 354 -485 -6 483 -6 -3 -361 58 3 -3 246 -8 -4 122 172 -212 10 -188 6 -4 -60 -483 -222 -1 -366 -18 1 -117 -256 -419 -10 212 -2 -14...
output:
impossible
result:
ok single line: 'impossible'
Test #10:
score: 0
Accepted
time: 2ms
memory: 4280kb
input:
1000 500 20 20 500 500 500 10 180 -12 18 184 324 39 8 -441 -20 -11 182 422 270 5 321 -5 14 -15 53 490 1 -496 -12 14 -15 262 -31 -6 250 -19 7 -324 203 -210 8 68 -15 -7 92 131 480 1 -373 14 5 52 -347 -124 8 46 3 -17 162 394 47 -7 417 -6 3 -173 -33 111 9 -46 -13 -2 138 491 398 -10 -498 17 9 202 -344 33...
output:
impossible
result:
ok single line: 'impossible'
Test #11:
score: 0
Accepted
time: 55ms
memory: 28508kb
input:
40000 5000 5000 5000 5000 5000 5000 5000 4712 -4246 -3569 -2508 -502 -3965 1152 4221 -1238 -502 3638 -1816 -785 -484 -284 -1802 2845 940 -7 3329 319 -4869 -2196 -1187 -3358 -977 -4598 1464 2731 1530 -889 1697 -650 -3009 2293 2985 -1348 -3496 -3319 -4620 -941 -4068 3380 4323 -3622 3803 1999 -1527 347...
output:
impossible
result:
ok single line: 'impossible'
Test #12:
score: 0
Accepted
time: 33ms
memory: 16116kb
input:
50000 1 1 1 1 1 1 4994 -1 1 1 -1 -1 1 3938 -1 1 1 -1 -1 1 -1193 1 -1 1 1 1 1 1739 -1 1 1 -1 1 -1 4977 1 -1 -1 1 1 -1 -4624 -1 1 -1 1 -1 -1 718 -1 -1 1 -1 -1 -1 -3181 1 1 -1 -1 -1 1 -3473 1 1 -1 -1 -1 -1 544 1 1 1 1 -1 -1 -677 1 1 -1 1 1 1 4701 -1 1 1 1 -1 -1 -4164 -1 -1 -1 1 1 1 -472 1 1 1 1 1 1 -35...
output:
impossible
result:
ok single line: 'impossible'
Test #13:
score: 0
Accepted
time: 32ms
memory: 16324kb
input:
50000 1 1 1 1 1 1 4994 1 -1 1 1 1 -1 4090 -1 -1 1 1 1 -1 1070 1 -1 1 -1 -1 1 2518 1 1 -1 -1 -1 1 -588 -1 -1 -1 1 1 -1 894 -1 1 1 1 1 1 -216 1 1 1 -1 1 1 -3055 1 -1 1 1 1 1 3376 1 1 -1 -1 1 1 -428 -1 1 1 1 -1 -1 -1420 -1 1 1 -1 1 1 4025 1 -1 -1 -1 1 1 3713 1 -1 1 1 -1 -1 -4496 -1 1 -1 -1 1 1 -790 1 1...
output:
impossible
result:
ok single line: 'impossible'
Test #14:
score: 0
Accepted
time: 9ms
memory: 9320kb
input:
10000 1000 1000 1000 1000 1000 1000 1000 -279 -71 970 583 -485 -256 -439 -459 303 -784 -636 -503 -560 -91 -947 923 329 -961 989 -118 -531 -659 -458 -523 -320 -425 963 -595 73 -868 -742 976 81 -595 216 332 -685 883 657 708 182 797 758 -395 672 -232 412 150 639 81 525 858 -888 843 -175 -819 -686 897 4...
output:
impossible
result:
ok single line: 'impossible'
Test #15:
score: 0
Accepted
time: 13ms
memory: 9220kb
input:
10000 1000 1000 1000 1000 1000 1000 1000 998 1000 -200 -901 622 941 -362 -608 -330 366 544 -341 -428 -318 -302 435 -114 -233 -777 -735 -295 -421 896 -424 606 -33 -496 -601 245 -41 -535 747 -330 443 -365 -289 643 -866 -976 325 -49 99 -186 127 189 100 528 257 -574 -780 -955 -241 -568 -800 -722 663 -37...
output:
impossible
result:
ok single line: 'impossible'
Test #16:
score: 0
Accepted
time: 39ms
memory: 23324kb
input:
50000 1000 1000 1000 1000 1000 1000 1000 -305 862 -527 463 -204 199 -158 805 -733 614 528 996 917 316 -273 -334 -698 862 -811 49 432 159 99 822 906 485 -881 402 -820 373 -462 -111 -869 684 -609 -480 -112 842 -370 900 683 -429 -653 472 -620 -200 -85 -490 -709 -964 -310 740 491 28 710 -972 -811 -617 -...
output:
impossible
result:
ok single line: 'impossible'
Test #17:
score: 0
Accepted
time: 83ms
memory: 40252kb
input:
50000 10000 10000 10000 10000 10000 10000 10000 6033 4235 8203 7263 -4695 -801 -2308 7461 2512 -9858 -2039 -2807 -8160 9562 -5427 -9345 -3202 -324 -1624 -9303 6654 -2998 3627 3038 5527 9830 -6543 -2317 -3632 9282 7248 -8264 7907 -5347 3574 -8529 -8453 7626 -8725 -5318 -3811 -5914 -4216 -8639 8663 25...
output:
impossible
result:
ok single line: 'impossible'
Test #18:
score: 0
Accepted
time: 86ms
memory: 40308kb
input:
50000 10000 10000 10000 10000 10000 10000 10000 -6529 -348 3680 3690 -2720 -8171 -6717 -535 -373 2263 -4067 303 9944 -5267 -6959 -1454 557 -443 -3818 6226 -6972 -3941 -5436 -7139 4971 6426 -5649 -8255 1805 -2129 5339 651 -9840 -4942 -2774 -8623 2367 -773 -9162 2835 3571 -782 -3902 -8742 9320 4626 -8...
output:
impossible
result:
ok single line: 'impossible'
Test #19:
score: 0
Accepted
time: 2ms
memory: 4168kb
input:
1000 500 20 20 500 500 500 10 -54 -10 8 -82 -205 500 2 320 8 -9 133 50 415 -6 -311 3 8 -404 -451 -293 2 -249 20 -14 314 90 154 3 406 9 -14 274 -352 277 10 -197 20 11 57 -445 248 3 -357 -5 -16 -407 -499 415 -2 -89 14 6 -240 -464 344 2 -395 -15 -17 135 421 47 3 425 -15 18 -32 388 65 -4 144 20 -7 373 -...
output:
possible
result:
ok single line: 'possible'
Test #20:
score: 0
Accepted
time: 2ms
memory: 4172kb
input:
1000 500 20 20 500 500 500 10 -137 -8 -6 254 69 65 -9 467 -5 19 436 -293 -264 1 -191 -4 -6 -500 184 428 -3 13 -3 1 -464 -495 170 9 109 -6 -16 42 200 313 6 310 -13 -17 349 -440 -328 4 -63 2 -17 356 183 306 -3 166 12 -5 -331 488 303 4 458 7 -14 -213 349 324 -9 -124 -20 -15 19 -153 413 5 168 1 -8 166 -...
output:
possible
result:
ok single line: 'possible'
Test #21:
score: 0
Accepted
time: 46ms
memory: 22556kb
input:
40000 5000 5000 5000 5000 5000 5000 5000 -4893 1892 2422 4622 4524 4363 -4142 466 2253 978 -3262 3229 108 -1053 499 4634 383 3075 2233 4548 -2178 3690 3227 3851 3581 -2395 -3853 -425 1586 2557 -4469 1866 -1656 594 -1014 4824 -1607 -73 3522 4001 -2867 3505 2127 -2402 -677 2719 -1120 989 2882 3900 172...
output:
possible
result:
ok single line: 'possible'
Test #22:
score: 0
Accepted
time: 26ms
memory: 16224kb
input:
50000 1 1 1 1 1 1 4994 1 1 -1 1 1 1 -1176 1 1 1 1 -1 1 4914 1 1 1 1 1 -1 1154 -1 1 1 1 1 1 -1948 -1 1 1 1 1 1 -835 1 1 1 1 -1 1 866 1 -1 1 1 1 1 2221 1 -1 1 1 1 1 1113 1 1 1 -1 1 1 378 1 1 1 1 1 1 754 1 1 1 1 1 1 3372 1 -1 1 1 1 1 3415 1 1 1 1 1 -1 1287 1 1 1 1 1 1 -2395 1 1 1 1 1 1 -4023 1 1 1 -1 1...
output:
possible
result:
ok single line: 'possible'
Test #23:
score: 0
Accepted
time: 26ms
memory: 16324kb
input:
50000 1 1 1 1 1 1 4994 1 1 -1 1 1 1 312 1 1 1 1 1 -1 3329 1 1 1 1 1 1 -1972 1 1 1 1 1 1 1627 1 1 1 1 -1 1 -2669 1 1 1 1 1 1 -1481 1 -1 1 1 1 1 -1933 1 1 1 1 1 1 2874 1 1 1 1 1 -1 -3358 -1 1 1 1 1 1 -4658 1 1 1 1 1 1 2594 1 1 -1 1 1 1 -2721 1 1 1 1 1 -1 -1636 1 1 1 1 -1 1 -2193 1 1 -1 1 1 1 4232 1 1 ...
output:
possible
result:
ok single line: 'possible'
Test #24:
score: 0
Accepted
time: 8ms
memory: 7944kb
input:
10000 1000 1000 1000 1000 1000 1000 1000 -980 -599 793 -876 482 135 -236 491 -316 624 216 767 368 297 -382 -313 -995 231 -776 -180 395 888 131 186 916 484 -26 899 329 524 494 -203 63 35 -231 549 -885 587 785 -294 -391 8 -272 515 -215 -215 45 -986 710 530 379 746 -405 -779 429 587 -308 -54 72 -368 -2...
output:
possible
result:
ok single line: 'possible'
Test #25:
score: 0
Accepted
time: 6ms
memory: 8000kb
input:
10000 1000 1000 1000 1000 1000 1000 1000 735 -241 193 811 -849 -939 574 278 441 -55 -297 670 -962 -736 -292 -337 635 829 24 83 -398 -558 738 -857 -350 -335 -396 420 -883 -836 519 382 -155 67 -611 479 700 104 126 880 -164 -93 -923 -302 -721 -434 581 992 -792 89 -359 -91 18 737 72 924 -91 876 454 -96 ...
output:
possible
result:
ok single line: 'possible'
Test #26:
score: 0
Accepted
time: 38ms
memory: 23004kb
input:
50000 1000 1000 1000 1000 1000 1000 1000 -210 -637 -580 -718 963 869 -504 291 -413 854 149 907 787 877 -627 -503 -22 -162 -748 385 -451 825 864 -373 -652 -445 110 -50 -403 452 481 666 -437 960 -819 -532 200 867 -582 824 463 86 296 -979 227 472 -314 -925 -556 96 892 158 899 -759 -938 442 -227 973 855...
output:
possible
result:
ok single line: 'possible'
Test #27:
score: 0
Accepted
time: 68ms
memory: 29044kb
input:
50000 10000 10000 10000 10000 10000 10000 10000 7609 -179 -9580 -833 6450 8118 8678 2291 2666 8828 8551 -7811 2981 -3673 1283 -1304 -4355 -3583 7620 -2662 8961 8685 4966 527 2502 2186 -6466 -9008 2264 -2613 1111 7901 -7860 4890 -8755 -5050 1843 4794 3092 -3203 -3789 7703 7739 -1256 9650 -5023 -7033 ...
output:
possible
result:
ok single line: 'possible'
Test #28:
score: 0
Accepted
time: 78ms
memory: 29104kb
input:
50000 10000 10000 10000 10000 10000 10000 10000 3986 -3862 7759 -8718 7314 2910 -636 6646 9909 3091 -7731 -3490 9620 -9659 4841 -8674 -4827 -6804 4302 -1915 -5638 -9307 4332 -2457 6013 -1670 6815 -9194 2690 3526 -2657 6787 -8759 -6658 -5441 -1813 526 8450 -5920 8097 9944 -8841 -9299 7151 4117 2383 -...
output:
possible
result:
ok single line: 'possible'
Test #29:
score: 0
Accepted
time: 26ms
memory: 16572kb
input:
50000 10 10 10 10 10 10 10 -2 4 2 2 6 -8 6 -2 5 -3 8 8 -10 -3 8 -4 -1 -10 5 -6 4 10 -3 -7 -10 1 -9 9 -7 3 -9 6 -9 5 1 -9 -3 -1 6 -5 10 8 5 8 -3 5 10 10 -5 4 3 -8 10 4 -5 -5 -1 -4 -3 -9 6 -4 10 4 -3 -1 -7 6 2 4 9 -1 10 -6 6 1 1 -2 5 3 9 2 -7 3 5 10 -2 5 6 1 -7 4 -8 4 4 -7 6 -1 3 -7 -4 5 -3 -7 -4 -6 7...
output:
impossible
result:
ok single line: 'impossible'
Test #30:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
3 3 3 3 3 3 3 3 3 1 2 1 3 1 2 -2 -1 2 3 -1 3 2 2 3 1 2 3 -1 2 3 2
output:
impossible
result:
ok single line: 'impossible'