結果
問題 | No.14 最小公倍数ソート |
ユーザー | ciel |
提出日時 | 2014-11-16 17:34:44 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 3,408 ms / 5,000 ms |
コード長 | 628 bytes |
コンパイル時間 | 1,046 ms |
コンパイル使用メモリ | 48,868 KB |
実行使用メモリ | 6,992 KB |
最終ジャッジ日時 | 2023-08-30 07:18:40 |
合計ジャッジ時間 | 40,096 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 51 ms
6,896 KB |
testcase_04 | AC | 3,408 ms
6,920 KB |
testcase_05 | AC | 1,131 ms
6,964 KB |
testcase_06 | AC | 1,363 ms
6,964 KB |
testcase_07 | AC | 1,775 ms
6,984 KB |
testcase_08 | AC | 2,353 ms
6,944 KB |
testcase_09 | AC | 3,166 ms
6,940 KB |
testcase_10 | AC | 3,134 ms
6,916 KB |
testcase_11 | AC | 3,226 ms
6,992 KB |
testcase_12 | AC | 3,319 ms
6,924 KB |
testcase_13 | AC | 3,364 ms
6,952 KB |
testcase_14 | AC | 3,278 ms
6,944 KB |
testcase_15 | AC | 3,351 ms
6,920 KB |
testcase_16 | AC | 1,340 ms
6,892 KB |
testcase_17 | AC | 964 ms
6,880 KB |
testcase_18 | AC | 436 ms
6,868 KB |
testcase_19 | AC | 2,175 ms
6,980 KB |
ソースコード
#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); }