結果

問題 No.854 公平なりんご分配
ユーザー maspy
提出日時 2020-03-18 15:18:28
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
実行時間 -
コード長 1,187 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 60,868 KB
最終ジャッジ日時 2024-12-14 02:08:41
合計ジャッジ時間 54,739 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 2
other RE * 92
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3.8
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

N = int(readline())
A = np.array(readline().split(), np.int32)
Q = int(readline())
PLR = np.array(read().split(), np.int32)
P = PLR[::3]
L = PLR[1::3]
R = PLR[2::3]


U = 2010
is_prime = np.zeros(U, np.bool)
is_prime[2] = 1
is_prime[3::2] = 1
for p in range(3, U, 2):
    if p * p >= U:
        break
    if is_prime[p]:
        is_prime[p * p::p + p] = 0
primes = np.where(is_prime)[0].tolist()

A_nonzero = (A != 0)


def calc_ord(A, p):
    ord_A = np.zeros_like(A)
    while True:
        q, r = np.divmod(A, p)
        divisible = r == 0 & (A_nonzero)
        if not np.any(divisible):
            return ord_A
        ord_A[divisible] += 1
        A[divisible] = q[divisible]


def solve(p):
    ord_A = calc_ord(A, p)
    ord_P = calc_ord(P, p)
    cum = np.zeros(len(ord_A) + 1, np.int32)
    cum[1:] = np.cumsum(ord_A)
    x = cum[R] - cum[L - 1]
    return x >= ord_P


ok = np.ones(Q, np.bool)
for p in primes[:5]:
    ok &= solve(p)
ok &= (P == 1)

answer = np.where(ok, 'Yes', 'NO')
print('\n'.join(answer))
0