結果

問題 No.14 最小公倍数ソート
ユーザー k
提出日時 2014-10-31 13:09:10
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 854 bytes
コンパイル時間 1,309 ms
コンパイル使用メモリ 72,852 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-12-30 15:20:59
合計ジャッジ時間 72,248 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 WA * 9 TLE * 8
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:32:41: warning: format ‘%llu’ expects argument of type ‘long long unsigned int*’, but argument 2 has type ‘ll*’ {aka ‘long unsigned int*’} [-Wformat=]
   32 |   for (int i = 0; i < n; i++) scanf("%llu", &a[i]);
      |                                      ~~~^   ~~~~~
      |                                         |   |
      |                                         |   ll* {aka long unsigned int*}
      |                                         long long unsigned int*
      |                                      %lu
main.cpp:35:15: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 2 has type ‘ll’ {aka ‘long unsigned int’} [-Wformat=]
   35 |   printf ("%llu ", a[0]);
      |            ~~~^    ~~~~
      |               |       |
      |               |       ll {aka long unsigned int}
      |               long long unsigned int
      |            %lu
main.cpp:44:17: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 2 has type ‘ll’ {aka ‘long unsigned int’} [-Wformat=]
   44 |     printf ("%llu ", a[p]);
      |              ~~~^    ~~~~
      |                 |       |
      |                 |       ll {aka long unsigned int}
      |                 long long unsigned int
      |              %lu
main.cpp:32:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |   for (int i = 0; i < n; i++) scanf("%llu", &a[i]);
      |                               ~~~~~^~~~~~~~~~~~~~~

ソースコード

diff #

#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <string>

using namespace std;

typedef uint64_t ll;

ll gcd(ll a, ll b){
   if(b==0)return a;
   else return gcd(b, a%b);
}

ll lcm(ll a, ll b){
   return a / gcd(a,b) * b;
}

int main() {
  ll n;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++) scanf("%llu", &a[i]);
  sort(a+1, a+n);

  printf ("%llu ", a[0]);
  for (int i = 0; i < n-1; i++) {
    ll mini = 1000000000;
    int p = 0;
    for (int j = i+1; j < n; j++) {
      ll t = lcm(a[i], a[j]);
      if (mini > t) p = j;
      mini = min(mini, t);
    }
    printf ("%llu ", a[p]);
    swap(a[p], a[i+1]);
  }
}
0