QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#278369#5559. Guessing Gamejzh#AC ✓95ms34324kbC++233.0kb2023-12-07 15:12:342023-12-07 15:12:35

Judging History

你现在查看的是最新测评结果

  • [2023-12-07 15:12:35]
  • 评测
  • 测评结果:AC
  • 用时:95ms
  • 内存:34324kb
  • [2023-12-07 15:12:34]
  • 提交

answer

#include<bits/stdc++.h>
#include <numeric>

using namespace std;

struct TwoSat {
    int n;
    std::vector<std::vector<int>> e;
    std::vector<bool> ans;
    TwoSat(int n) : n(n), e(2 * n), ans(n) {}
    void addClause(int u, bool f, int v, bool g) {
        e[2*u+f].push_back(2*v+g);
    }
    bool satisfiable() {
        std::vector<int> id(2 * n, -1), dfn(2 * n, -1), low(2 * n, -1);
        std::vector<int> stk;
        int now = 0, cnt = 0;
        std::function<void(int)> tarjan = [&](int u) {
            stk.push_back(u);
            dfn[u] = low[u] = now++;
            for (auto v : e[u]) {
                if (dfn[v] == -1) {
                    tarjan(v);
                    low[u] = std::min(low[u], low[v]);
                } else if (id[v] == -1) {
                    low[u] = std::min(low[u], dfn[v]);
                }
            }
            if (dfn[u] == low[u]) {
                int v;
                do {
                    v = stk.back();
                    stk.pop_back();
                    id[v] = cnt;
                } while (v != u);
                ++cnt;
            }
        };
        for (int i = 0; i < 2 * n; ++i) if (dfn[i] == -1) tarjan(i);
        for (int i = 0; i < n; ++i) {
            if (id[2 * i] == id[2 * i + 1]) return false;
            ans[i] = id[2 * i] > id[2 * i + 1];
        }
        return true;
    }
    std::vector<bool> answer() { return ans; }
};

void solve() {
	int n; cin >> n;
	vector<int>sz(7);
	for(int i = 0 ; i < 7 ; i ++) cin >> sz[i];

	int m = accumulate(begin(sz), end(sz), 0);
	TwoSat ts(m);

	for(int i = 1 ; i < 7 ; i ++) sz[i] += sz[i-1];

	auto id = [&](int day, int num) {
		if(day==0) return abs(num)-1;
		else return sz[day-1] + abs(num) - 1;
	};


	vector<bool>vis(2*m);
	for(int tt = 0 ; tt < n ; tt ++) {
		vector<int>vec(7);
		for(int i = 0 ; i < 7 ; i ++) cin >> vec[i];
		for(int i = 0 ; i < 7 ; i ++) {
			for(int j = i + 1 ; j < 7 ; j ++) {
				int u = id(i, vec[i]);
				int v = id(j, vec[j]);

				bool f1 = vec[i]>0;
				bool f2 = vec[j]>0;

				//if(u==19 and (v==21 or v==24)) {
				//	cout << u << ' ' << f1 << ' ' << v << ' ' << f2 << endl;
				//}

				ts.addClause(u, f1, v, !f2);
				ts.addClause(v, f2, u, !f1);

				vis[2*u+f1] = true;
				vis[2*v+f2] = true;
			}
		}
	}

	bool flag = true;
	for(int i = 0 ; i < 2*m ; i += 2) {
		flag &= !(vis[i] & vis[i+1]);
	}

	int v1, v2; cin >> v1 >> v2;

	int u1 = id(5, v1); bool f1 = v1>0;
	int u2 = id(6, v2); bool f2 = v2>0;

	if(flag and !vis[2*u1+f1]) {
		cout << "possible\n";
		return;
	}
	if(flag and !vis[2*u2+f2]) {
		cout << "possible\n";
		return;
	}

	ts.addClause(u1, !f1, u1, f1);
	ts.addClause(u2, !f2, u2, f2);

	//cout << u1 << ' ' << f1 << ' ' << u2 << ' ' << f2 << endl;

	if(ts.satisfiable()) {
		cout << "possible\n";
	}
	else{
		cout << "impossible\n";
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	solve();

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3796kb

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: 3824kb

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: 3560kb

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: 3576kb

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: 3632kb

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: 3572kb

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: 3624kb

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: 3620kb

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: 4180kb

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: 4108kb

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: 66ms
memory: 24080kb

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: 23ms
memory: 12624kb

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: 30ms
memory: 12752kb

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: 13ms
memory: 8084kb

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: 8340kb

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: 43ms
memory: 19376kb

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: 93ms
memory: 34288kb

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: 95ms
memory: 34324kb

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: 3992kb

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: 4112kb

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: 54ms
memory: 19036kb

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: 35ms
memory: 12672kb

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: 35ms
memory: 12700kb

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: 12ms
memory: 7080kb

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: 12ms
memory: 7140kb

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: 28ms
memory: 19332kb

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: 78ms
memory: 24480kb

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: 91ms
memory: 24408kb

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: 27ms
memory: 13216kb

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: 3664kb

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'