Submission #1227450
Source Code Expand
import random def tester(N=0): ''' 制約 1≦N≦2000 1≦Ai≦108 ''' maxno1=20 maxno2=1e5 s=input() if s!='': return(s) if N==0: #return(6) return(random.randint(2,maxno1)) else: print('Testing...') print('N=',N) #return('1 2 3 4 5 2') A=[] for i in range(N): A.extend([random.randint(1,maxno2)]) r=' '.join(list(map(str,A))) return(r) def factorint(n): i = 2 T = [] while i * i <= n: while n % i == 0: n //= i T.append(i) i += 1 if n > 1: T.append(n) return(T) import logging # create logger logger = logging.getLogger('simple_example') logger.setLevel(logging.WARNING)#DEBUG) # create console handler and set level to debug ch = logging.StreamHandler() ch.setLevel(logging.WARNING) #DEBUG) # create formatter formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') # add formatter to ch ch.setFormatter(formatter) # add ch to logger logger.addHandler(ch) import copy N=int(tester()) A=[int(x) for x in tester(N).split()] A.sort(reverse=False) logger.debug('A is %s',str(A)) F=dict() P=dict() for i in range(N): if A[i]==1: F[i]={1} else: F[i]=set(factorint(A[i])) for y in F[i]: if y not in P.keys(): P[y]=set() P[y].add(i) G=dict() for i in F.keys(): G[i]=set() for y in F[i]: G[i]=G[i].union(P[y]) G[i].remove(i) Ac=list(range(N)) Gc=copy.deepcopy(G) Tr=dict() while len(Ac)>0: Tmp=[] rt=min(Ac) me=rt Tmp.extend([me]) Ac.remove(me) while len(Gc[me])>0: nxt=min(Gc[me]) if nxt not in Ac: Gc[me].remove(nxt) continue else: me=nxt Tmp.extend([me]) Ac.remove(me) Tr[rt]=Tmp OoTr=list(Tr.keys()) OoTr.sort(reverse=True) AnsIdx=[] for i in OoTr: AnsIdx.extend(Tr[i]) for i in range(N): for j in range(N-1,i,-1): if AnsIdx[j-1]<AnsIdx[j]: if F[AnsIdx[j-1]]&F[AnsIdx[j]]==set(): AnsIdx[j-1],AnsIdx[j]=AnsIdx[j],AnsIdx[j-1] Ans=[A[i] for i in AnsIdx] print(' '.join(list(map(str,Ans)))) logger.removeHandler(ch)
Submission Info
Submission Time | |
---|---|
Task | E - Rearranging |
User | Pgmto70 |
Language | Python (3.4.3) |
Score | 0 |
Code Size | 2099 Byte |
Status | WA |
Exec Time | 2117 ms |
Memory | 222112 KB |
Judge Result
Set Name | Sample | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 1600 | ||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample1.txt, sample2.txt |
All | sample1.txt, sample2.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in3.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, in38.txt, in39.txt, in4.txt, in40.txt, in41.txt, in42.txt, in43.txt, in44.txt, in45.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
in1.txt | TLE | 2114 ms | 165596 KB |
in10.txt | TLE | 2115 ms | 183404 KB |
in11.txt | TLE | 2105 ms | 29792 KB |
in12.txt | TLE | 2105 ms | 30248 KB |
in13.txt | TLE | 2105 ms | 29720 KB |
in14.txt | TLE | 2105 ms | 29844 KB |
in15.txt | TLE | 2105 ms | 29856 KB |
in16.txt | TLE | 2117 ms | 215336 KB |
in17.txt | TLE | 2116 ms | 221216 KB |
in18.txt | TLE | 2117 ms | 217884 KB |
in19.txt | TLE | 2117 ms | 222112 KB |
in2.txt | TLE | 2114 ms | 168628 KB |
in20.txt | TLE | 2116 ms | 218916 KB |
in21.txt | AC | 694 ms | 8240 KB |
in22.txt | AC | 660 ms | 8236 KB |
in23.txt | WA | 675 ms | 8228 KB |
in24.txt | AC | 630 ms | 8236 KB |
in25.txt | AC | 645 ms | 8232 KB |
in26.txt | TLE | 2105 ms | 30060 KB |
in27.txt | TLE | 2105 ms | 29996 KB |
in28.txt | TLE | 2104 ms | 31556 KB |
in29.txt | TLE | 2105 ms | 30312 KB |
in3.txt | TLE | 2113 ms | 161404 KB |
in30.txt | TLE | 2105 ms | 30304 KB |
in31.txt | AC | 33 ms | 4664 KB |
in32.txt | AC | 33 ms | 4664 KB |
in33.txt | AC | 33 ms | 4664 KB |
in34.txt | AC | 657 ms | 8172 KB |
in35.txt | AC | 661 ms | 8228 KB |
in36.txt | TLE | 2107 ms | 48088 KB |
in37.txt | TLE | 2107 ms | 48216 KB |
in38.txt | TLE | 2106 ms | 50104 KB |
in39.txt | TLE | 2107 ms | 48352 KB |
in4.txt | TLE | 2114 ms | 161368 KB |
in40.txt | TLE | 2106 ms | 47572 KB |
in41.txt | TLE | 2106 ms | 49552 KB |
in42.txt | TLE | 2107 ms | 47708 KB |
in43.txt | TLE | 2107 ms | 47976 KB |
in44.txt | TLE | 2106 ms | 47584 KB |
in45.txt | TLE | 2107 ms | 48212 KB |
in5.txt | TLE | 2114 ms | 161816 KB |
in6.txt | TLE | 2114 ms | 170200 KB |
in7.txt | TLE | 2114 ms | 170476 KB |
in8.txt | TLE | 2114 ms | 170280 KB |
in9.txt | TLE | 2113 ms | 162232 KB |
sample1.txt | AC | 33 ms | 4664 KB |
sample2.txt | AC | 33 ms | 4664 KB |