====== 고득점 ====== ===== 풀이 ===== * [[ps:problems:programmers:42860]]과 동일한 문제. 풀이는 그쪽을 참조. ===== 코드 ===== """Solution code for "BOJ 3663. 고득점". - Problem link: https://www.acmicpc.net/problem/3663 - Solution link: http://www.teferi.net/ps/problems/boj/3663 Tags: [Greedy] """ ORD_A = ord('A') def main(): T = int(input()) for _ in range(T): name = input() u_d_count = sum(min(ord(c) - ORD_A, ORD_A - ord(c) + 26) for c in name) if u_d_count == 0: print(0) continue t = [i for i, c in enumerate(name) if c != 'A'] l_r_count = len(name) - t[0] for i in range(len(t) - 1): left, right = len(name) - t[i + 1], t[i] l_r_count = min(l_r_count, left * 2 + right, right * 2 + left) l_r_count = min(l_r_count, t[-1]) print(u_d_count + l_r_count) if __name__ == '__main__': main() {{tag>BOJ ps:problems:boj:골드_4}}