結果

問題 No.276 連続する整数の和(1)
ユーザー nanaenanae
提出日時 2018-07-28 07:37:28
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,829 bytes
コンパイル時間 619 ms
コンパイル使用メモリ 95,888 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 20:50:13
合計ジャッジ時間 1,321 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.d(27): Deprecation: usage of the `body` keyword is deprecated. Use `do` instead.
Main.d(40): Deprecation: usage of the `body` keyword is deprecated. Use `do` instead.
Main.d(53): Deprecation: usage of the `body` keyword is deprecated. Use `do` instead.
Main.d(62): Deprecation: usage of the `body` keyword is deprecated. Use `do` instead.
/dmd2/linux/bin64/../../src/phobos/std/numeric.d(2999): Warning: cannot inline function `std.numeric.gcdImpl!ulong.gcdImpl`

ソースコード

diff #

import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;


void main() {
    long n;
    scan(n);
    writeln(gcd(n, n*(n-1)/2));
}





struct UnionFind {
    private {
        int _size;
        int[] _parent;
        int _numcc;
    }

    this(int N) 
    in {
        assert(N > 0);
    }
    body {
        _size = N;
        _numcc = N;
        _parent = new int[](_size);
        foreach (i ; 0 .. _size) {
            _parent[i] = i;
        }
    }

    int findRoot(int x)
    in {
        assert(0 <= x && x < _size);
    }
    body {
        if (_parent[x] != x) {
            _parent[x] = findRoot(_parent[x]);
        }

        return _parent[x];
    }

    bool same(int x, int y)
    in {
        assert(0 <= x && x < _size);
        assert(0 <= y && y < _size);
    }
    body {
        return findRoot(x) == findRoot(y);
    }

    void merge(int x, int y)
    in {
        assert(0 <= x && x < _size);
        assert(0 <= y && y < _size);
    }
    body {
        int u = findRoot(x);
        int v = findRoot(y);

        if (u == v) return;

        _parent[v] = u;
        _numcc--;
    }

    int numcc() {
        return _numcc;
    }
}



































void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
0