結果

問題 No.3262 水色コーダーさん、その問題d問題ですよ?(1<=d<=N)
ユーザー yt142857
提出日時 2025-09-06 13:26:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 906 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 82,088 KB
実行使用メモリ 76,800 KB
最終ジャッジ日時 2025-09-06 13:26:39
合計ジャッジ時間 3,687 ms
ジャッジサーバーID
(参考情報)
judge / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
al = []
for i in range(n):
  a,b = map(int,input().split())
  al.append((a,b))
#次の順列を出力.もうなかったら-1を出します。
def Next_P(now):
  last_higher = -1
  nagasa = len(now)
  for i in range(nagasa-1):
    if now[i] < now[i+1]:
      last_higher = i
  if last_higher == -1:
    return -1
  else:
    last_higher_higher = -1
    for j in range(last_higher+1,nagasa):
      if now[last_higher] < now[j]:
        last_higher_higher = j
    now[last_higher],now[last_higher_higher] = now[last_higher_higher],now[last_higher]
    hanten = now[last_higher+1:]
    hanten = hanten[::-1]
    now = now[:last_higher+1] + hanten

    return now
now = list(range(n))
ans = 0
while now != -1:
  num = 0
  p = True
  for i in range(n):
    num = max(num,al[now[i]][0])
    if num > al[now[i]][1]:
      p = False
      break
  if p:
    ans += 1
  now = Next_P(now)
print(ans)
0