結果

問題 No.339 何人が回答したのか
ユーザー kichirb3
提出日時 2018-03-09 08:24:07
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,108 bytes
コンパイル時間 1,105 ms
コンパイル使用メモリ 83,052 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-07 04:20:36
合計ジャッジ時間 2,976 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 61
権限があれば一括ダウンロードができます

ソースコード

diff #

// No.339 何人が回答したのか
// https://yukicoder.me/problems/no/339
//

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
using namespace std;

unsigned int solve(vector<unsigned int> &answers, unsigned int N);
unsigned gcd(unsigned int u, unsigned int v);


unsigned gcd(unsigned int u, unsigned int v) {
    while ( v != 0) {
        unsigned int r = u % v;
        u = v;
        v = r;
    }
    return u;
}


int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    unsigned int N;
    cin >> N;
    vector<unsigned int> answers(N);
    for (auto i = 0; i < N; ++i)
        cin >> answers[i];

    unsigned int res = solve(answers, N);
    cout << res << endl;
}

unsigned int solve(vector<unsigned int> &answers, unsigned int N) {
    set<unsigned int> u_answers(answers.begin(), answers.end());

    unsigned int prev_gcd = *u_answers.begin();
    for (auto u:u_answers) {
        prev_gcd = gcd(prev_gcd, u);
    }

    unsigned int ans = 0;
    for (auto a: answers) {
        ans += a / prev_gcd;
    }
    return ans;
}
0