結果
| 問題 | No.101 ぐるぐる!あみだくじ! |
| コンテスト | |
| ユーザー |
izuru_matsuura
|
| 提出日時 | 2016-12-14 22:19:36 |
| 言語 | D (dmd 2.112.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,075 bytes |
| 記録 | |
| コンパイル時間 | 905 ms |
| コンパイル使用メモリ | 125,016 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2026-03-05 09:26:37 |
| 合計ジャッジ時間 | 2,349 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 |
コンパイルメッセージ
/home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/std/numeric.d(3011): Warning: cannot inline function `std.numeric.gcdImpl!uint.gcdImpl`
private typeof(T.init % T.init) gcdImpl(T)(T a, T b)
^
ソースコード
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void log(A...)(A arg) { stderr.writeln(arg); }
int size(T)(in T s) { return cast(int)s.length; }
void main() {
auto N = readln.chomp.to!int;
auto K = readln.chomp.to!int;
auto X = iota(0, N, 1).array;
foreach (i; 0 .. K) {
int x, y; readf("%s %s\n", &x, &y);
x--; y--;
swap(X[x], X[y]);
}
auto Y = iota(0, N, 1).array;
void step() {
auto nY = new int[N];
foreach (i; 0 .. N) {
nY[i] = Y[ X[i] ];
}
Y = nY;
}
int lcm(int a, int b) {
return a / gcd(a, b) * b;
}
int ans = 1;
auto used = new bool[N];
for (int t = 1; t <= N; t++) {
step();
foreach (i; 0 .. N) {
if (!used[i] && Y[i] == i) {
used[i] = true;
ans = lcm(ans, t);
}
}
}
writeln(ans);
}
izuru_matsuura