結果
問題 | No.2276 I Want AC |
ユーザー |
![]() |
提出日時 | 2023-05-10 16:35:13 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 726 ms / 2,000 ms |
コード長 | 2,421 bytes |
コンパイル時間 | 340 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 152,732 KB |
最終ジャッジ日時 | 2024-11-26 21:39:32 |
合計ジャッジ時間 | 26,268 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 56 |
ソースコード
###スニペット始まり### import sys, re from copy import copy, deepcopy from math import ceil, floor, sqrt,factorial, gcd, pi, degrees, radians, sin, asin, cos, acos, tan, atan2 from collections import Counter, deque, defaultdict from heapq import heapify, heappop, heappush from itertools import permutations, accumulate, product, combinations, combinations_with_replacement from bisect import bisect, bisect_left, bisect_right from functools import reduce, lru_cache from string import ascii_uppercase, ascii_lowercase from decimal import Decimal, ROUND_HALF_UP #四捨五入用 def input(): return sys.stdin.readline().rstrip('\n') #easy-testのpypyでは再帰数を下げる。 if __file__=='prog.py': sys.setrecursionlimit(10**5) else: sys.setrecursionlimit(10**6) def lcm(a, b): return a * b // gcd(a, b) #3つ以上の最大公約数/最小公倍数。Nを要素数、Mを数値の大きさとして、O(NlogM) def gcd_v2(l: list): return reduce(gcd, l) def lcm_v2(l: list): return reduce(lcm, l) #nPk def nPk(n, k): return factorial(n) // factorial(n - k) #逆元 def modinv(a, mod=10**9+7): return pow(a, mod-2, mod) INF = float('inf') MOD = 10 ** 9 + 7 ###スニペット終わり### N=int(input()) S=list(input()) hatena_idx=[] for i, s in enumerate(S): if s=='?': hatena_idx.append(i) def is_ok(mid): #一つ目 s=S.copy() for i, idx in enumerate(hatena_idx): if i<mid: s[idx]='A' else: s[idx]='C' counter=Counter() cnt1=0 for i in range(N): if s[-(i+1)]=='A': cnt1+=counter['C'] counter[s[-(i+1)]]+=1 #二つ目 s=S.copy() for i, idx in enumerate(hatena_idx): if i<mid-1: s[idx]='A' else: s[idx]='C' counter=Counter() cnt2=0 for i in range(N): if s[-(i+1)]=='A': cnt2+=counter['C'] counter[s[-(i+1)]]+=1 return cnt2<=cnt1 def meguru_bisect(ng, ok): while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok ans=meguru_bisect(len(hatena_idx)+1, 0) s=S.copy() for i, idx in enumerate(hatena_idx): if i<ans: s[idx]='A' else: s[idx]='C' counter=Counter() cnt1=0 for i in range(N): if s[-(i+1)]=='A': cnt1+=counter['C'] counter[s[-(i+1)]]+=1 print(cnt1)