CSES - HIIT Open 2019 - Results
Submission details
Task:HIIT Speedrun
Sender:.*
Submission time:2019-05-25 12:10:54 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.02 sdetails
#2ACCEPTED0.02 sdetails
#3ACCEPTED0.03 sdetails
#4ACCEPTED0.02 sdetails
#5ACCEPTED0.08 sdetails
#6ACCEPTED0.03 sdetails
#7ACCEPTED0.02 sdetails
#8ACCEPTED0.02 sdetails
#9ACCEPTED0.03 sdetails
#10ACCEPTED0.02 sdetails
#11ACCEPTED0.02 sdetails
#12ACCEPTED0.02 sdetails
#13ACCEPTED0.09 sdetails

Compiler report

input/code.cpp: In function 'void haku(int, int, int, int)':
input/code.cpp:20:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<ee[ind1].size(); i++) {
               ~^~~~~~~~~~~~~~~~
input/code.cpp:21:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int ii=0; ii<ee[ind2].size(); ii++) {
                 ~~^~~~~~~~~~~~~~~~
input/code.cpp:24:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int iii=0; iii<ee[ind3].size(); iii++) {
                   ~~~^~~~~~~~~~~~~~~~
input/code.cpp:27:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int iiii=0; iiii<ee[ind4].size(); iiii++) {
                     ~~~~^~~~~~~~~~~~~~~~

Code

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define M 1000000007
#define N (1<<18)
#define P complex<long long>
#define X real()
#define Y imag()

using namespace std;

int n, m, a, b, z[101];
string s;
ll d[101][101], ans = 1e9;
vector<int> vrk[101];
vector<int> ee[3]; // H I T

void haku(int ind1, int ind2, int ind3, int ind4) {
	for(int i=0; i<ee[ind1].size(); i++) {
		for(int ii=0; ii<ee[ind2].size(); ii++) {
				if(ee[ind1][i] == ee[ind2][ii])
					continue;
			for(int iii=0; iii<ee[ind3].size(); iii++) {
					if(ee[ind1][i] == ee[ind3][iii] || ee[ind2][ii] == ee[ind3][iii])
						continue;
				for(int iiii=0; iiii<ee[ind4].size(); iiii++) {
					if(ee[ind1][i] == ee[ind4][iiii] || ee[ind2][ii] == ee[ind4][iiii] || ee[ind3][iii] == ee[ind4][iiii])
						continue;
					ans = min(ans, d[1][ee[ind1][i]]+d[ee[ind1][i]][ee[ind2][ii]]+d[ee[ind2][ii]][ee[ind3][iii]]+d[ee[ind3][iii]][ee[ind4][iiii]]+d[ee[ind4][iiii]][n]);
				}
			}
		}
	}
}

int main() {
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	cin >> n >> m;
	cin >> s;
	s = "#" + s;
	for(int i=1; i<=n; i++) {
		if(s[i] == 'H') {
			ee[0].push_back(i);
		} else if(s[i] == 'I') {
			ee[1].push_back(i);
		} else if(s[i] == 'T') {
			ee[2].push_back(i);
		}
	}
	for(int i=0; i<m; i++) {
		cin >> a >> b;
		vrk[a].push_back(b);
		vrk[b].push_back(a);
	}
	for(int i=0; i<=n; i++) {
		for(int j=1; j<=n; j++)
			d[i][j] = 1e9;
	}
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=n; j++)
			z[j] = 0;
		queue<pair<int,int>> q;
		q.push(make_pair(i,0));
		while(!q.empty()) {
			int s = q.front().first;
			int dii = q.front().second;
			q.pop();
			if(z[s])
				continue;
			z[s] = 1;
			d[i][s] = dii;
			for(auto u:vrk[s]) {
				if(z[u])
					continue;
				q.push(make_pair(u, dii+1));
			}
		}
	}
	vector<int> vv;
	vv.push_back(0);
	vv.push_back(1);
	vv.push_back(1);
	vv.push_back(2);
	sort(vv.begin(), vv.end());
	do {
		haku(vv[0], vv[1], vv[2], vv[3]);
	} while(next_permutation(vv.begin(), vv.end()));
	if(ans == 1e9)
		cout << "IMPOSSIBLE";
	else
		cout << ans;
}

Test details

Test 1

Verdict: ACCEPTED

input
4 0
HIIT

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 2

Verdict: ACCEPTED

input
4 3
HIIT
1 2
2 3
3 4

correct output
3

user output
3

Test 3

Verdict: ACCEPTED

input
4 3
HIIT
4 3
3 2
2 1

correct output
3

user output
3

Test 4

Verdict: ACCEPTED

input
6 5
XHIITX
1 2
1 3
1 4
...

correct output
9

user output
9

Test 5

Verdict: ACCEPTED

input
100 5000
TIIIIIIITHHHTHHHIHIIHIHHHITHIH...

correct output
3

user output
3

Test 6

Verdict: ACCEPTED

input
100 99
HIIIIIIIIIIIIIIIIIIIIIIIIIIIII...

correct output
99

user output
99

Test 7

Verdict: ACCEPTED

input
10 10
AAAHIITAAA
1 2
2 3
3 4
...

correct output
9

user output
9

Test 8

Verdict: ACCEPTED

input
9 9
HIIIIIIIT
1 2
2 3
3 4
...

correct output
4

user output
4

Test 9

Verdict: ACCEPTED

input
9 9
HIIIIAAAT
1 2
2 3
3 4
...

correct output
5

user output
5

Test 10

Verdict: ACCEPTED

input
100 99
HIIIIIIIIIIIIIIIIIIIIIIIIIIIII...

correct output
197

user output
197

Test 11

Verdict: ACCEPTED

input
8 8
HIITHIIT
1 2
2 3
3 4
...

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 12

Verdict: ACCEPTED

input
6 5
HIIITI
1 2
2 3
3 4
...

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 13

Verdict: ACCEPTED

input
100 99
HHHHHHHHHHHHHHHHHHHHHHHHHIIIII...

correct output
99

user output
99