Submission #62829567


Source Code Expand

Copy
N,K = map(int,input().split())
A = list(map(int,input().split()))
# bigM = 1200000
bigM = 1000000 # N<10^6
def solve():
# A_iO(N)
arr1 = [0]*(bigM+1)
for a_i in A:
arr1[a_i] += 1
# A_iO(N log N)
arr2 = [0]*(bigM+1)
arr2[1] = N # 1 A_i
for p in range(2,bigM+1):
for q in range(1,bigM+1):
if p * q > bigM:
break
arr2[p] += arr1[p * q] # parr2
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
N,K = map(int,input().split())
A = list(map(int,input().split()))

# bigM = 1200000
bigM = 1000000 # N<10^6 だったので改めた

def solve():

    # 全てのA_iに対してカウントする配列を作る。計算量はO(N)
    arr1 = [0]*(bigM+1)
    for a_i in A:
        arr1[a_i] += 1

    # 全てのA_iの約数に対してカウントする配列を作る。計算量はO(N log N)
    arr2 = [0]*(bigM+1)
    arr2[1] = N  # 1 は全てのA_iの約数のため
    for p in range(2,bigM+1):
        for q in range(1,bigM+1):
            if p * q > bigM:
                break
            arr2[p] += arr1[p * q]  # pを約数とする数をarr2に取得

    # 1~bigM までの組み合わせの数がarr2に入っているので、その数がK以上であれば使えるとしてarr3に約数を格納していく。計算量はO(N log N)
    arr3 = [1]*(bigM+1)  # この配列には約数が入るのだが、全ての整数は1を約数とするため、1を入れておく。
    for p in range(2,bigM+1):
        for q in range(1,bigM+1):
            if p * q > bigM:
                break
            if arr2[p] >= K:  # K回以上使用している場合
                arr3[p * q] = p  # p*qの約数としてpを代入。同じ数字(p*q)の約数としては後の値が優先される

    # 求まった約数を出力する
    for a in A:
        print(arr3[a])

solve()

Submission Info

Submission Time
Task E - GCD of Subset
User yasubei
Language Python (PyPy 3.10-v7.3.12)
Score 475
Code Size 1440 Byte
Status AC
Exec Time 464 ms
Memory 296012 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 3
AC × 35
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 02_a_distinct_00.txt, 02_a_distinct_01.txt, 02_a_distinct_02.txt, 02_a_distinct_03.txt, 02_a_distinct_04.txt, 03_a_max_00.txt, 03_a_max_01.txt, 03_a_max_02.txt, 03_a_max_03.txt, 03_a_max_04.txt, 03_a_max_05.txt, 03_a_max_06.txt, 04_hcn_00.txt, 04_hcn_01.txt, 04_hcn_02.txt, 04_hcn_03.txt, 04_hcn_04.txt, 04_hcn_05.txt, 04_hcn_06.txt, 04_hcn_07.txt, 04_hcn_08.txt, 05_corner_00.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 180 ms 105384 KB
00_sample_01.txt AC 146 ms 105720 KB
00_sample_02.txt AC 180 ms 105632 KB
01_random_00.txt AC 326 ms 203344 KB
01_random_01.txt AC 410 ms 287996 KB
01_random_02.txt AC 451 ms 279808 KB
01_random_03.txt AC 439 ms 288432 KB
01_random_04.txt AC 415 ms 232992 KB
01_random_05.txt AC 440 ms 288124 KB
01_random_06.txt AC 349 ms 216700 KB
01_random_07.txt AC 440 ms 288260 KB
01_random_08.txt AC 454 ms 213416 KB
01_random_09.txt AC 464 ms 283328 KB
02_a_distinct_00.txt AC 414 ms 274148 KB
02_a_distinct_01.txt AC 409 ms 274088 KB
02_a_distinct_02.txt AC 416 ms 274216 KB
02_a_distinct_03.txt AC 354 ms 274384 KB
02_a_distinct_04.txt AC 414 ms 274272 KB
03_a_max_00.txt AC 415 ms 288840 KB
03_a_max_01.txt AC 359 ms 288744 KB
03_a_max_02.txt AC 412 ms 288704 KB
03_a_max_03.txt AC 411 ms 288632 KB
03_a_max_04.txt AC 406 ms 288504 KB
03_a_max_05.txt AC 408 ms 296012 KB
03_a_max_06.txt AC 402 ms 295872 KB
04_hcn_00.txt AC 401 ms 288604 KB
04_hcn_01.txt AC 400 ms 288744 KB
04_hcn_02.txt AC 396 ms 288912 KB
04_hcn_03.txt AC 400 ms 288588 KB
04_hcn_04.txt AC 399 ms 288908 KB
04_hcn_05.txt AC 409 ms 288520 KB
04_hcn_06.txt AC 403 ms 288892 KB
04_hcn_07.txt AC 402 ms 288608 KB
04_hcn_08.txt AC 403 ms 288952 KB
05_corner_00.txt AC 151 ms 105644 KB


2025-04-03 (Thu)
18:43:55 +00:00