Created
June 30, 2019 17:04
-
-
Save kusano/67181db5a2fb17e9ca68a567dd22aa5a to your computer and use it in GitHub Desktop.
Facebook Hacker Cup 2019 Round 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| T = input() | |
| for t in range(T): | |
| N, M = map(int, raw_input().split()) | |
| R = [] | |
| for _ in range(M): | |
| X, Y, Z = map(int, raw_input().split()) | |
| R += [(X-1, Y-1, Z)] | |
| oo = 999999999 | |
| G = [[oo]*N for _ in range(N)] | |
| for r in R: | |
| G[r[0]][r[1]] = r[2] | |
| G[r[1]][r[0]] = r[2] | |
| for i in range(N): | |
| for j in range(N): | |
| for k in range(N): | |
| G[j][k] = min(G[j][k], G[j][i]+G[i][k]) | |
| ok = True | |
| for r in R: | |
| if G[r[0]][r[1]] != r[2]: | |
| ok = False | |
| print "Case #%d:"%(t+1), | |
| if ok: | |
| print len(R) | |
| for r in R: | |
| print r[0]+1, r[1]+1, r[2] | |
| else: | |
| print "Impossible" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| T = input() | |
| for t in range(T): | |
| N, K = map(int, raw_input().split()) | |
| V = list(raw_input()) | |
| c = 0 | |
| ans = 0 | |
| for i in xrange(N-1, -1, -1): | |
| c += 1 if V[i]=="B" else -1 | |
| if c>K: | |
| ans += 1<<(i+1) | |
| c -= 2 | |
| c = max(c, 0) | |
| print "Case #%d: %d" % (t+1, ans%(10**9+7)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment