結果
| 問題 |
No.14 最小公倍数ソート
|
| ユーザー |
|
| 提出日時 | 2014-11-16 17:34:44 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3,639 ms / 5,000 ms |
| コード長 | 628 bytes |
| コンパイル時間 | 793 ms |
| コンパイル使用メモリ | 44,800 KB |
| 実行使用メモリ | 7,168 KB |
| 最終ジャッジ日時 | 2024-12-31 21:00:16 |
| 合計ジャッジ時間 | 41,240 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:19:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
19 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
main.cpp:21:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
21 | for(int i=0;i<n;i++)scanf("%d",&v[i].second);
| ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#include <vector>
#include <algorithm>
#include <cstdio>
#define N 1000
using namespace std;
int memo[N][N];
int gcd(int x,int y){
if(!y)return x;
if(x<N&&y<N){
if(memo[x][y])return memo[x][y];
return memo[x][y]=gcd(y,x%y);
}
return gcd(y,x%y);
}
int lcm(int x,int y){return x/gcd(x,y)*y;}
int main(){
int n,s=0;
scanf("%d",&n);
vector<pair<int,int> >v(n);
for(int i=0;i<n;i++)scanf("%d",&v[i].second);
for(int i=0;i<n-2;i++){
for(int j=i+1;j<n;j++)v[j].first=lcm(v[i].second,v[j].second);
sort(v.begin()+i+1,v.end());
}
for(int i=0;i<n;i++)printf(i<n-1?"%d ":"%d\n",v[i].second);
}