목차

착신 전환 소동

ps
링크acmicpc.net/…
출처BOJ
문제 번호31409
문제명착신 전환 소동
레벨실버 3
분류

애드혹, 해 구성하기

시간복잡도O(n)
인풋사이즈n<=100,000
사용한 언어Python 3.11
제출기록42036KB / 108ms
최고기록84ms
해결날짜2024/02/19
출처

제3회 보라매컵 본선 Open Contest - B

풀이

코드

"""Solution code for "BOJ 31409. 착신 전환 소동".

- Problem link: https://www.acmicpc.net/problem/31409
- Solution link: http://www.teferi.net/ps/problems/boj/31409

Tags: [ad hoc]
"""


def main():
    N = int(input())
    a = [int(x) for x in input().split()]

    count = 0
    for i, a_i in enumerate(a):
        if i == a_i - 1:
            a[i] = i
            count += 1
    if a[0] == 0:
        a[0] = N

    print(count)
    print(*a)


if __name__ == '__main__':
    main()