結果

問題 No.1905 PURE PHRASE
ユーザー Theta
提出日時 2022-10-11 18:58:32
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,128 ms / 2,000 ms
コード長 833 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 62,672 KB
最終ジャッジ日時 2024-06-25 13:44:34
合計ジャッジ時間 44,775 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
外部呼び出し有り
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

from scipy.fft import fft
import numpy as np


heltz = {
    "C4": 261.6,
    "D4": 294.3,
    "E4": 327.0,
    "F4": 348.8,
    "G4": 392.4,
    "A4": 436.0,
    "B4": 490.5
}


def main():
    _ = input()
    A = list(map(int, input().split()))
    A_fft = fft(A)
    A_fft_abs = np.abs(A_fft)
    A_fft_freq = np.fft.fftfreq(44100, d=1/44100)
    main_frequency = A_fft_freq[np.where(A_fft_abs > np.max(A_fft_abs)/10)]
    sound_errors = {}
    for sound_name, freq in heltz.items():
        relative_frequency = main_frequency / freq
        relative_frequency_rounded = np.round(relative_frequency)
        sound_errors[sound_name] = np.linalg.norm(
            relative_frequency-relative_frequency_rounded)

    print(min(sound_errors, key=lambda sound_name: sound_errors[sound_name]))


if __name__ == "__main__":
    main()
0