Skip to content

Commit

Permalink
DICTIONARY 180ms
Browse files Browse the repository at this point in the history
  • Loading branch information
Queue-ri committed Feb 27, 2022
1 parent 542aa05 commit 3fc536c
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions DEF/DICTIONARY/Queue-ri.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import sys
from collections import defaultdict
input = sys.stdin.readline

def main():
adj = None
visited = None
order = None

def check(order):
order = order[::-1]
for i in range(1, len(order)):
j = i-1
if adj[order[i]][order[j]]: return False
return order

def dfs(c):
visited[c] = 1
for e in adj[c]:
if not visited[e]:
dfs(e)
order.append(c)

for TC in range(int(input())):
adj = defaultdict(lambda: defaultdict(int))
N = int(input())
words = []
for i in range(N): words.append(input().rstrip())
for i in range(1, N): # adj initialization
j = i-1
L = min(len(words[j]), len(words[i]))
for k in range(L):
if words[j][k] != words[i][k]:
adj[words[j][k]][words[i][k]] = 1
break # following characters are meaningless

visited = defaultdict(int)
order = []
for c in reversed('abcdefghijklmnopqrstuvwxyz'):
if not visited[c]: dfs(c)
order = check(order)
print(''.join(order) if order else 'INVALID HYPOTHESIS')

if __name__ == '__main__':
main()

1 comment on commit 3fc536c

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AOJI Report

โœ” Your code has been accepted!

๐ŸŽฏ AOJ Result

Judge ID Problem ID Language Result Performance
741096 DICTIONARY py3 ์ •๋‹ต 204ms

โš  Performance doesn't match. (ยฑ4ms might be a temporary AOJ error)

๐Ÿ“ข Python code has a wider error range in AOJ.

๐ŸŽฏ Tested Commit

Hash Language File Path Performance
3fc536c py3 DEF/DICTIONARY/Queue-ri.py 180ms

๐ŸŽฏ Submission Log

Click here to extend
Request to https://algospot.com/accounts/login/?next=/
<Response [200]>

# AOJI UUID: 94d8db0a-9d7a-4a27-aeb7-260563eb7853
# This code was submitted by AOJI from https://github.com/Queue-ri/Advanced-Algorithm-Study.
# Please contact [email protected] if there's any problem.

import sys
from collections import defaultdict
input = sys.stdin.readline

def main():
    adj = None
    visited = None
    order = None

    def check(order):
        order = order[::-1]
        for i in range(1, len(order)):
            j = i-1
            if adj[order[i]][order[j]]: return False
        return order

    def dfs(c):
        visited[c] = 1
        for e in adj[c]:
            if not visited[e]:
                dfs(e)
        order.append(c)

    for TC in range(int(input())):
        adj = defaultdict(lambda: defaultdict(int))
        N = int(input())
        words = []
        for i in range(N): words.append(input().rstrip())
        for i in range(1, N): # adj initialization
            j = i-1
            L = min(len(words[j]), len(words[i]))
            for k in range(L):
                if words[j][k] != words[i][k]:
                    adj[words[j][k]][words[i][k]] = 1
                    break # following characters are meaningless

        visited = defaultdict(int)
        order = []
        for c in reversed('abcdefghijklmnopqrstuvwxyz'):
            if not visited[c]: dfs(c)
        order = check(order)
        print(''.join(order) if order else 'INVALID HYPOTHESIS')

if __name__ == '__main__':
    main()
Request to https://algospot.com/judge/problem/submit/DICTIONARY
<Response [200]>

+----+--------+------------+-------+------+-------+------+--------+--------+
|    |      # | ๋ฌธ์ œ         | ์ œ์ถœ์ž   | ์–ธ์–ด   | ๊ธธ์ด    | ๊ฒฐ๊ณผ   | ์ˆ˜ํ–‰์‹œ๊ฐ„   | ์ œ์ถœ์‹œ๊ฐ„   |
|----+--------+------------+-------+------+-------+------+--------+--------|
|  0 | 741096 | DICTIONARY | 0x10  | py3  | 1.4KB | ์ •๋‹ต   | 204ms  | ๋ฐฉ๊ธˆ ์ „   |
|  1 | 741094 | DICTIONARY | 0x10  | py3  | 1.4KB | ์ •๋‹ต   | 180ms  | 5๋ถ„ ์ „   |
+----+--------+------------+-------+------+-------+------+--------+--------+
----
Parsed: 94d8db0a-9d7a-4a27-aeb7-260563eb7853 from 741096
----
[AOJ Result]
- Judge ID: 741096
- Problem ID: DICTIONARY
- Language: py3
- Result: ์ •๋‹ต
- Performance: 204ms

1.0.0-alpha.4 | Developer | Workflow

Please sign in to comment.