結果
問題 | No.14 最小公倍数ソート |
ユーザー | ciel |
提出日時 | 2014-11-16 17:32:46 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 3,480 ms / 5,000 ms |
コード長 | 628 bytes |
コンパイル時間 | 1,071 ms |
コンパイル使用メモリ | 49,064 KB |
実行使用メモリ | 7,012 KB |
最終ジャッジ日時 | 2023-08-30 07:12:42 |
合計ジャッジ時間 | 40,807 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 50 ms
6,884 KB |
testcase_04 | AC | 3,480 ms
6,952 KB |
testcase_05 | AC | 1,147 ms
6,928 KB |
testcase_06 | AC | 1,372 ms
6,924 KB |
testcase_07 | AC | 1,790 ms
6,980 KB |
testcase_08 | AC | 2,361 ms
6,936 KB |
testcase_09 | AC | 3,164 ms
7,012 KB |
testcase_10 | AC | 3,133 ms
6,952 KB |
testcase_11 | AC | 3,228 ms
6,952 KB |
testcase_12 | AC | 3,319 ms
6,956 KB |
testcase_13 | AC | 3,347 ms
7,008 KB |
testcase_14 | AC | 3,271 ms
7,008 KB |
testcase_15 | AC | 3,391 ms
6,948 KB |
testcase_16 | AC | 1,331 ms
6,936 KB |
testcase_17 | AC | 955 ms
6,968 KB |
testcase_18 | AC | 449 ms
6,900 KB |
testcase_19 | AC | 2,220 ms
6,996 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); }