QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB

#23972. Distance

Statistics

問題文

N 個のボールが 1 列に並べてある.左から順にボール 1,2,…,N と呼ぶ.ボール i は色 Ci で塗られている.

各 i=1,2,…,N について,以下の値を求めよ.

  • ボール i と色が等しいすべてのボールに対する,ボール i との距離の総和.ただし,ボール i とボール j の距離は |i-j| で定義される.

制約

  • 1 ≦ N ≦ 100.
  • 1 ≦ Ci≦ 100 (1 ≦ i ≦ N).
  • 入力される値はすべて整数である.

入力

入力は以下の形式で与えられる.
N
C1 C2 … CN

出力

N 行にわたり出力せよ.i 行目 (1 ≦ i ≦ N) には,ボール i と色が等しいすべてのボールに対する,ボール i との距離の総和を出力せよ.

答え以外は何も出力しないこと.(入力を促す文章なども出力しないこと.)

解答形式については,練習問題やその解答例を参考にしても良い.


入力例 1

4
1   2   1   1

出力例 1

5
0
3
4

ボール 1 が色 1 で,ボール 2 が色 2 で,ボール 3 が色 1 で,ボール 4 が色 1 で塗られている.

  • i = 1 について,ボール 1 と色が等しいボールはボール 1,3,4 であり,それぞれボール 1 との距離は 0,2,3 なので 0+2+3=5 を出力する.
  • i = 2 について,ボール 2 と色が等しいボールはボール 2 のみであり,ボール 2 との距離は 0 なので 0 を出力する.
  • i = 3 について,ボール 3 と色が等しいボールはボール 1,3,4 であり,それぞれボール 3 との距離は 2,0,1 なので 2+0+1=3 を出力する.
  • i = 4 について,ボール 4 と色が等しいボールはボール 1,3,4 であり,それぞれボール 4 との距離は 3,1,0 なので 3+1+0=4 を出力する.

入力例 2

1
100

出力例 2

0

ボール 1 が色 100 で塗られている.

  • i = 1 について,ボール 1 と色が等しいボールはボール 1 のみであり,ボール 1 との距離は 0 なので 0 を出力する.

入力例 3

8
1   3   9   7   3   3   7   9

出力例 3

0
7
5
3
4
5
3
5

入力例 4

10
1   1   1   1   1   1   1   1   1   1

出力例 4

45
37
31
27
25
25
27
31
37
45

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.