結果
問題 |
No.1738 What's in the box?
|
ユーザー |
![]() |
提出日時 | 2021-11-13 19:56:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 835 bytes |
コンパイル時間 | 419 ms |
コンパイル使用メモリ | 41,472 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-27 20:33:17 |
合計ジャッジ時間 | 2,596 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 70 |
ソースコード
/* -*- coding: utf-8 -*- * * 1738.cc: No.1738 What's in the box? - yukicoder */ #include<cstdio> #include<algorithm> using namespace std; /* constant */ const int MAX_N = 1000; /* typedef */ typedef long long ll; /* global variables */ int ws[MAX_N]; /* subroutines */ template <typename T> T gcd(T m, T n) { // m > 0, n > 0 if (m < n) swap(m, n); while (n > 0) { T r = m % n; m = n; n = r; } return m; } /* main */ int main() { int n, m; scanf("%d%d", &n, &m); ll wsum = 0; for (int i = 0; i < n; i++) { scanf("%d", ws + i); wsum += ws[i]; } ll u = 0, v = 1; if (m > 0) { ll g = gcd(wsum, (ll)m); // 1/x = u/v = m/wsum u = m / g, v = wsum / g; } for (int i = 0; i < n; i++) printf("%lld%c", ws[i] * u / v, (i + 1 < n) ? ' ' : '\n'); return 0; }