Submission #51435892
Source Code Expand
""" <方針> - 英小文字(`26`種類)がそれぞれ何文字あるかを数える. - 異なる英小文字同士でスワップすれば,その分だけ通りがある. - 最後に,自分同士の入れ替えするパターンも記録しておく. """ S = input() # それぞれの英小文字(26種類)が何文字あるかを数える. ls = [0]*26 for s in S: ls[ord(s)-ord("a")] += 1 # この2重ループにおけるスワップする条件 # 条件1: 自分同士のすわっぷは考えない.(なぜなら,自分同士のスワップは特殊であり,後でやるから) # 条件2: 2回スワップしないように,iとjでは必ず,i<jとなるようにする. ans = 0 for i in range(26): for j in range(26): # 上述の条件1, 条件2より,i<jのときのみスワップする. if(i<j): # スワップするパターン分答えを増やす. ans += ls[i]*ls[j] # 同じ英小文字が存在する時は,答えを1だけ増やす.その時は,ちょうど一回だけ増やす必要がある. for i in range(26): if(ls[i]>1): ans += 1 break print(ans)
Submission Info
Submission Time | |
---|---|
Task | C - One Time Swap |
User | mattsunkun |
Language | Python (PyPy 3.10-v7.3.12) |
Score | 350 |
Code Size | 1182 Byte |
Status | AC |
Exec Time | 78 ms |
Memory | 83308 KiB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 350 / 350 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example_00.txt, example_01.txt |
All | example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
example_00.txt | AC | 61 ms | 76104 KiB |
example_01.txt | AC | 60 ms | 75836 KiB |
hand_00.txt | AC | 71 ms | 82000 KiB |
hand_01.txt | AC | 62 ms | 76232 KiB |
hand_02.txt | AC | 61 ms | 76244 KiB |
hand_03.txt | AC | 62 ms | 75848 KiB |
hand_04.txt | AC | 62 ms | 76192 KiB |
hand_05.txt | AC | 78 ms | 83252 KiB |
hand_06.txt | AC | 77 ms | 83308 KiB |
random_00.txt | AC | 61 ms | 75848 KiB |
random_01.txt | AC | 61 ms | 75968 KiB |
random_02.txt | AC | 61 ms | 76188 KiB |
random_03.txt | AC | 61 ms | 75868 KiB |
random_04.txt | AC | 61 ms | 75880 KiB |
random_05.txt | AC | 77 ms | 83012 KiB |
random_06.txt | AC | 77 ms | 83080 KiB |
random_07.txt | AC | 78 ms | 82880 KiB |
random_08.txt | AC | 78 ms | 82832 KiB |
random_09.txt | AC | 78 ms | 83216 KiB |
random_10.txt | AC | 77 ms | 83256 KiB |
random_11.txt | AC | 78 ms | 82772 KiB |
random_12.txt | AC | 78 ms | 82632 KiB |
random_13.txt | AC | 77 ms | 83000 KiB |
random_14.txt | AC | 76 ms | 83056 KiB |