結果

問題 No.1905 PURE PHRASE
ユーザー Akidai16
提出日時 2022-08-01 14:56:14
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 1,320 bytes
コンパイル時間 3,832 ms
コンパイル使用メモリ 234,388 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-22 04:11:42
合計ジャッジ時間 5,844 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)
#define All(A) A.begin(), A.end()
#define rAll(A) A.rbegin(), A.rend()

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int N;
vi A;

void solve() {
    vector<pair<string, long double>> freqs = {
        {"C4", 261.6}, 
        {"D4", 294.3},
        {"E4", 327.0},
        {"F4", 348.8},
        {"G4", 392.4},
        {"A4", 436.0},
        {"B4", 490.5}
    };
    string ans = "";
    long min_error = LONG_MAX;
    for(pair<string, long double> freq: freqs) {
        long error_sum = 0.0;
        int shift = 44100 / freq.second;
        REP(i, 0, 44100) {
            if(i - shift <= 0) continue;
            error_sum += abs(A[i] - A[i - shift]);
        }
        if(min_error > error_sum) {
            ans = freq.first;
            min_error = error_sum;
        }
        // cout << error_sum << endl;
    }
    cout << ans << endl;
}

int main() {
    cin >> N;
    A.resize(N);
    REP(i, 0, N) {
        cin >> A[i];
    }
    solve();
}
0