GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Sunday 4 September 2022

[Solution] Circular Mirror Codeforces Solution



C. Circular Mirror
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Pak Chanek has a mirror in the shape of a circle. There are N lamps on the circumference numbered from 1 to N in clockwise order. The length of the arc from lamp i to lamp i+1 is Di for 1iN1. Meanwhile, the length of the arc between lamp N and lamp 1 is DN.

Pak Chanek wants to colour the lamps with M different colours. Each lamp can be coloured with one of the M colours. However, there cannot be three different lamps such that the colours of the three lamps are the same and the triangle made by considering the three lamps as vertices is a right triangle (triangle with one of its angles being exactly 90 degrees).

The following are examples of lamp colouring configurations on the circular mirror.

Before colouring the lamps, Pak Chanek wants to know the number of distinct colouring configurations he can make. Count the number of distinct possible lamp colouring configurations, modulo 998244353.

Input

The first line contains two integers N and M (1N31052M3105) — the number of lamps in the mirror and the number of different colours used.

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

The second line contains N integers D1,D2,,DN (1Di109) — the lengths of the arcs between the lamps in the mirror.

Output

An integer representing the number of possible lamp colouring configurations, modulo 998244353.

Note

In the first example, all correct lamp colouring configurations are [1,1,2,1][1,1,2,2][1,2,1,2][1,2,2,1][1,2,2,2][2,1,1,1][2,1,1,2][2,1,2,1][2,2,1,1], and [2,2,1,2].

No comments:

Post a Comment