結果
問題 | No.1738 What's in the box? |
ユーザー |
![]() |
提出日時 | 2021-11-12 21:42:55 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 599 bytes |
コンパイル時間 | 2,053 ms |
コンパイル使用メモリ | 193,772 KB |
最終ジャッジ日時 | 2025-01-25 16:11:56 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 70 |
ソースコード
#include <bits/stdc++.h>using namespace std;long long gcd(long long a,long long b) {if(a == 0 || b == 0) {return max(a,b);}if(a % b == 0) {return b;}else {return gcd(b,a % b);}}int main() {int N,M;cin >> N >> M;long long sum = 0;vector<int>W(N);for(int i = 0; i < N; i++) {cin >> W[i];sum += W[i];}long long g = gcd(sum,M);if(g) {sum /= g;M /= g;}for(int i = 0; i < N; i++) {cout << (sum == 0?0:W[i]/sum*M) << ((i+1 == N)?"\n":" ");}}