Submission #1231337
Source Code Expand
import random def tester(N=0): ''' 制約 1≦N≦2000 1≦Ai≦108 ''' maxno1=2000 maxno2=1e5 s=input() if s!='': return(s) if N==0: return(2000) return(random.randint(2,maxno1)) else: print('Testing...') print('N=',N) #return('2 3 4 6') 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 = set() while i * i <= n: while n % i == 0: n //= i T.add(i) i += 1 if n > 1: T.add(n) return(T) import logging import time # create logger logger = logging.getLogger('simple_example') logger.setLevel(logging.WARNING) #logger.setLevel(logging.DEBUG) # create console handler and set level to debug ch = logging.StreamHandler() ch.setLevel(logging.WARNING) #ch.setLevel(logging.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()] start_time = time.time() 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]=factorint(A[i]) for pn in F[i]: if pn not in P.keys(): P[pn]=set() P[pn].add(i) stepcount=1 logger.debug('Step %d: loss = %.2f (%.3f sec)' % (stepcount, 100, time.time() - start_time)) G=dict() for i in F.keys(): G[i]=set() for y in F[i]: for z in P[y]: G[i].add(z) stepcount=2 logger.debug('Step %d: loss = %.2f (%.3f sec)' % (stepcount, 100, time.time() - start_time)) Ac=set(range(N)) stepcount=21 logger.debug('Step %d: loss = %.2f (%.3f sec)' % (stepcount, 100, time.time() - start_time)) Gc=copy.copy(G) Tr=dict() stepcount=22 logger.debug('Step %d: loss = %.2f (%.3f sec)' % (stepcount, 100, time.time() - start_time)) while len(Ac)>0: Tmp=[] rt=Ac.pop() me=rt Tmp.extend([me]) while len(Gc[me])>0: nxt=Gc[me].pop() if nxt in Ac: #Gc[nxt]=Gc[nxt]-{me} me=nxt Tmp.extend([me]) Ac.remove(me) Tr[rt]=Tmp stepcount=3 logger.debug('Step %d: loss = %.2f (%.3f sec)' % (stepcount, 100, time.time() - start_time)) OoTr=list(Tr.keys()) OoTr.sort(reverse=True) AnsIdx=[] for i in OoTr: AnsIdx.extend(Tr[i]) stepcount=4 logger.debug('Step %d: loss = %.2f (%.3f sec)' % (stepcount, 100, time.time() - start_time)) 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)))) stepcount=5 logger.debug('Step %d: loss = %.2f (%.3f sec)' % (stepcount, 100, time.time() - start_time)) logger.removeHandler(ch)
Submission Info
Submission Time | |
---|---|
Task | E - Rearranging |
User | Pgmto70 |
Language | Python (3.4.3) |
Score | 0 |
Code Size | 2921 Byte |
Status | WA |
Exec Time | 2111 ms |
Memory | 112696 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 | 2081 ms | 71864 KB |
in10.txt | TLE | 2110 ms | 90204 KB |
in11.txt | WA | 1106 ms | 18360 KB |
in12.txt | WA | 1093 ms | 18820 KB |
in13.txt | WA | 1181 ms | 18408 KB |
in14.txt | WA | 1087 ms | 18492 KB |
in15.txt | WA | 1172 ms | 18448 KB |
in16.txt | TLE | 2111 ms | 109240 KB |
in17.txt | TLE | 2111 ms | 111416 KB |
in18.txt | TLE | 2111 ms | 108472 KB |
in19.txt | TLE | 2110 ms | 112696 KB |
in2.txt | TLE | 2089 ms | 74440 KB |
in20.txt | TLE | 2111 ms | 108340 KB |
in21.txt | WA | 609 ms | 7096 KB |
in22.txt | WA | 600 ms | 7096 KB |
in23.txt | WA | 638 ms | 7224 KB |
in24.txt | WA | 597 ms | 7096 KB |
in25.txt | WA | 750 ms | 7096 KB |
in26.txt | WA | 1116 ms | 18664 KB |
in27.txt | WA | 1151 ms | 18656 KB |
in28.txt | WA | 1177 ms | 18460 KB |
in29.txt | WA | 1087 ms | 18676 KB |
in3.txt | TLE | 2103 ms | 68988 KB |
in30.txt | WA | 1078 ms | 18704 KB |
in31.txt | AC | 35 ms | 4664 KB |
in32.txt | AC | 35 ms | 4664 KB |
in33.txt | AC | 34 ms | 4668 KB |
in34.txt | AC | 644 ms | 7172 KB |
in35.txt | AC | 580 ms | 7144 KB |
in36.txt | WA | 1234 ms | 23096 KB |
in37.txt | WA | 1143 ms | 23116 KB |
in38.txt | WA | 1241 ms | 23220 KB |
in39.txt | WA | 1161 ms | 23224 KB |
in4.txt | TLE | 2108 ms | 68152 KB |
in40.txt | WA | 1203 ms | 22840 KB |
in41.txt | WA | 1165 ms | 22968 KB |
in42.txt | WA | 1167 ms | 22712 KB |
in43.txt | WA | 1170 ms | 22956 KB |
in44.txt | WA | 1257 ms | 22712 KB |
in45.txt | WA | 1180 ms | 23096 KB |
in5.txt | TLE | 2108 ms | 69240 KB |
in6.txt | TLE | 2091 ms | 73144 KB |
in7.txt | TLE | 2108 ms | 71868 KB |
in8.txt | TLE | 2099 ms | 74700 KB |
in9.txt | TLE | 2045 ms | 69024 KB |
sample1.txt | AC | 35 ms | 4664 KB |
sample2.txt | AC | 35 ms | 4664 KB |