CSES - HIIT Open 2018 - Results
Submission details
Task:Monotonic
Sender:Ukkonen Fan Club
Submission time:2018-05-26 14:13:46 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.01 sdetails
#2ACCEPTED0.23 sdetails
#3ACCEPTED0.34 sdetails
#4ACCEPTED1.46 sdetails
#5ACCEPTED0.17 sdetails
#6ACCEPTED0.19 sdetails
#7ACCEPTED0.26 sdetails
#8ACCEPTED0.30 sdetails
#9ACCEPTED0.10 sdetails
#10ACCEPTED0.09 sdetails

Code

#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
vector<pair<int, int> > prog;
int transition[1<<15];
void solve() {
	int n,m;
	cin>>n>>m;
	prog.resize(m);
	for(int i = 0; i < m; ++i) {
		cin>>prog[i].F>>prog[i].S;
		--prog[i].F;
		--prog[i].S;
	}
	for(int mask = 0; mask < (1<<n); ++mask) {
		int mask2 = mask;
		for(int i = 0; i < m; ++i) {
			int a = 1<<prog[i].F;
			int b = 1<<prog[i].S;
			if((mask2 & a) && (!(mask2&b))) {
				mask2 ^= a | b;
			}
		}
		transition[mask] = mask2;
	}
	int ma = 0;
	for(int mask = 0; mask < (1<<n); ++mask) {
		int mask2 = mask;
		int ones = __builtin_popcount(mask);
		int zeros = n - ones;
		int res = (1<<ones)-1;
		res <<= zeros;
		int moves = 0;
		for(int i = 0; i < 250; ++i) {
			if(mask2 == res) break;
			++moves;
			mask2 = transition[mask2];
		}
		ma = max(ma, moves);
	}
	if(ma == 250) ma = -1;

	cout<<ma<<'\n';
}
int main() {
	int tt;
	cin>>tt;
	for(int xx = 0; xx < tt; ++xx) {
		solve();
	}
}

Test details

Test 1

Verdict: ACCEPTED

input
3
4 4
1 2
3 4
1 2
...

correct output
-1
3
1

user output
-1
3
1

Test 2

Verdict: ACCEPTED

input
10
15 200
1 14
2 6
3 14
...

correct output
-1
-1
-1
-1
-1
...

user output
-1
-1
-1
-1
-1
...

Test 3

Verdict: ACCEPTED

input
10
15 350
1 14
2 6
3 14
...

correct output
3
-1
2
-1
1
...

user output
3
-1
2
-1
1
...

Test 4

Verdict: ACCEPTED

input
10
15 1500
1 14
2 6
3 14
...

correct output
1
1
1
1
1
...

user output
1
1
1
1
1
...

Test 5

Verdict: ACCEPTED

input
10
15 100
4 10
3 9
6 15
...

correct output
-1
-1
-1
-1
-1
...

user output
-1
-1
-1
-1
-1
...

Test 6

Verdict: ACCEPTED

input
10
15 200
4 5
2 12
7 8
...

correct output
-1
-1
-1
-1
-1
...

user output
-1
-1
-1
-1
-1
...

Test 7

Verdict: ACCEPTED

input
10
15 300
5 10
6 12
12 13
...

correct output
-1
-1
2
2
-1
...

user output
-1
-1
2
2
-1
...

Test 8

Verdict: ACCEPTED

input
10
15 400
10 13
2 14
8 13
...

correct output
-1
1
1
-1
1
...

user output
-1
1
1
-1
1
...

Test 9

Verdict: ACCEPTED

input
10
15 14
14 15
11 12
1 2
...

correct output
8
7
4
4
3
...

user output
8
7
4
4
3
...

Test 10

Verdict: ACCEPTED

input
10
15 14
1 2
2 3
3 4
...

correct output
14
7
5
4
3
...

user output
14
7
5
4
3
...