結果
| 問題 |
No.14 最小公倍数ソート
|
| コンテスト | |
| ユーザー |
k
|
| 提出日時 | 2014-10-31 14:14:21 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,251 bytes |
| コンパイル時間 | 696 ms |
| コンパイル使用メモリ | 65,716 KB |
| 最終ジャッジ日時 | 2025-01-28 21:00:34 |
| 合計ジャッジ時間 | 1,456 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:17:9: error: ‘uint64_t’ does not name a type
17 | typedef uint64_t ll;
| ^~~~~~~~
main.cpp:13:1: note: ‘uint64_t’ is defined in header ‘<cstdint>’; did you forget to ‘#include <cstdint>’?
12 | #include <cctype>
+++ |+#include <cstdint>
13 | #include <string>
main.cpp:19:1: error: ‘ll’ does not name a type
19 | ll gcd(ll a, ll b){
| ^~
main.cpp:24:1: error: ‘ll’ does not name a type
24 | ll lcm(ll a, ll b){
| ^~
main.cpp: In function ‘int main()’:
main.cpp:29:3: error: ‘ll’ was not declared in this scope
29 | ll n;
| ^~
main.cpp:30:10: error: ‘n’ was not declared in this scope; did you mean ‘yn’?
30 | cin >> n;
| ^
| yn
main.cpp:31:13: error: template argument 2 is invalid
31 | vector <ll> a(n);
| ^
main.cpp:32:47: error: invalid types ‘int[int]’ for array subscript
32 | for (int i = 0; i < n; i++) scanf("%llu", &a[i]);
| ^
main.cpp:33:10: error: request for member ‘begin’ in ‘a’, which is of non-class type ‘int’
33 | sort(a.begin()+1, a.end());
| ^~~~~
main.cpp:33:23: error: request for member ‘end’ in ‘a’, which is of non-class type ‘int’
33 | sort(a.begin()+1, a.end());
| ^~~
main.cpp:35:22: error: invalid types ‘int[int]’ for array subscript
35 | printf ("%llu ", a[0]);
| ^
main.cpp:37:7: error: expected ‘;’ before ‘mini’
37 | ll mini = 1000000000;
| ^~~~~
| ;
main.cpp:41:22: error: ‘mini’ was not declared in this scope
41 | if (p != -1 && mini < a[j]) break;
| ^~~~
main.cpp:41:30: error: invalid types ‘int[int]’ for array subscript
41 | if (p != -1 && mini < a[j]) break;
| ^
main.cpp:42:9: error: expected
ソースコード
#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;
vector <ll> a(n);
for (int i = 0; i < n; i++) scanf("%llu", &a[i]);
sort(a.begin()+1, a.end());
printf ("%llu ", a[0]);
for (int i = 0; i < n-1; i++) {
ll mini = 1000000000;
int p = -1;
for (int j = i+1; j < n; j++) {
if (p != -1 && mini < a[j]) break;
ll t = lcm(a[i], a[j]);
if (mini > t) p = j;
if (p != -1 && mini == t && a[p] > a[j]) p = j;
mini = min(mini, t);
}
printf ("%llu ", a[p]);
if (i == n-2) break;
if (i+1 == p) continue;
swap(a[p], a[i+1]);
// for (int j = 0; j < a.size(); j++) cout << a[j] << " ";
// cout << endl;
ll x = a[p]; a.erase(a.begin()+p);
a.insert(lower_bound(a.begin()+i+2, a.end(), x), x);
// sort(a+i+2, a+n);
}
}
k