結果

問題 No.1006 Share an Integer
ユーザー shi-moshi-mo
提出日時 2020-09-30 22:24:04
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 371 ms / 2,000 ms
コード長 684 bytes
コンパイル時間 1,453 ms
コンパイル使用メモリ 147,840 KB
実行使用メモリ 62,240 KB
最終ジャッジ日時 2023-09-04 10:11:28
合計ジャッジ時間 5,923 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 199 ms
36,436 KB
testcase_12 AC 347 ms
57,960 KB
testcase_13 AC 368 ms
62,240 KB
testcase_14 AC 370 ms
60,972 KB
testcase_15 AC 312 ms
52,488 KB
testcase_16 AC 147 ms
28,320 KB
testcase_17 AC 200 ms
37,388 KB
testcase_18 AC 314 ms
56,596 KB
testcase_19 AC 296 ms
51,764 KB
testcase_20 AC 328 ms
55,848 KB
testcase_21 AC 371 ms
60,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio;
import std.conv;
import std.array;
import std.math;
import std.algorithm;

void main() {
    int x; readf("%s\n", &x);

    int[] f = new int[](x+1);
    foreach (i; 1..(x+1)) {
        f[i] = i - 1;
    }
    foreach (i; 2..(x+1)) {
        for (int j = 0; j <= x; j += i) {
            f[j]--;
        }
    }

    int[][] p = new int[][](x);
    foreach (a; 1..(x/2 + 1)) {
        int b = x - a;
        int score = (f[a]-f[b]).abs;
        if (null == p[score]) p[score] = [];
        p[score] ~= a;
        if (b != a) p[score] ~= b;
    }

    int[] ans = p.find!((a) => null != a)[0];
    foreach(a; ans.sort()) {
        writef("%s %s\n", a, (x-a));
    }
}
0