s_id stringlengths 10 10 | p_id stringlengths 6 6 | u_id stringlengths 10 10 | date stringlengths 10 10 | language stringclasses 1
value | original_language stringclasses 11
values | filename_ext stringclasses 1
value | status stringclasses 1
value | cpu_time stringlengths 1 5 | memory stringlengths 1 7 | code_size stringlengths 1 6 | code stringlengths 1 539k |
|---|---|---|---|---|---|---|---|---|---|---|---|
s776819136 | p02242 | u845643816 | 1511969133 | Python | Python3 | py | Runtime Error | 0 | 0 | 742 | rootList = [-1 for i in range(n)]
parent = [0 for i in range(n)]
lenList = [float("inf") for i in range(n)]
lenList[0] = 0
def getRoot(x):
r = rootList[x]
if r < 0:
rootList[x] = x
elif r != x:
rootList[x] = getRoot(r)
return rootList[x]
flag = True
while flag:
flag = False
edge... |
s945333322 | p02242 | u626266743 | 1511970077 | Python | Python3 | py | Runtime Error | 0 | 0 | 940 | from sys import stdin
INFTY = 1 << 21
WHITE = 0
GRAY = 1
BLACK = 2
n = int(stdin.readline())
M = [[INFTY for i in range(n)] for j in range(n)]
for u in range(n):
U = list(map(int, stdin.readline().split()[2:]))
for j in range(0, len(U), 2):
M[u][U[j]] = U[j+1]
d = [INFTY for i in range(n)]
color = [... |
s329299363 | p02242 | u626266743 | 1511970106 | Python | Python3 | py | Runtime Error | 0 | 0 | 926 | from sys import stdin
INFTY = 1 << 21
WHITE = 0
GRAY = 1
BLACK = 2
n = int(stdin.readline())
M = [[INFTY] * n for i in range(n)]
for u in range(n):
U = list(map(int, stdin.readline().split()[2:]))
for j in range(0, len(U), 2):
M[u][U[j]] = U[j+1]
d = [INFTY for i in range(n)]
color = [WHITE for i in... |
s010523309 | p02242 | u626266743 | 1511970367 | Python | Python3 | py | Runtime Error | 0 | 0 | 952 | from sys import stdin
INFTY = 1 << 21
WHITE = 0
GRAY = 1
BLACK = 2
n = int(stdin.readline())
M = [[INFTY for i in range(n)] for j in range(n)]
for u in range(0, n):
U = list(map(int, stdin.readline().split()[2:]))
for j in range(0, len(U), 2):
M[u][U[j]] = U[j+1]
d = [INFTY for i in range(n)]
color ... |
s638264617 | p02243 | u007270338 | 1530999457 | Python | Python3 | py | Runtime Error | 0 | 0 | 1585 | #coding:utf-8
import numpy as np
n = int(input())
inf = 1000000000000000
def minHeapify(Q,i):
H = len(Q)
l = 2*i
r = 2*i + 1
if l < H and Q[l][1] < Q[i][1]:
smallest = l
else:
smallest = i
if r < H and Q[r][1] < Q[smallest][1]:
smallest = r
if smallest != i:
... |
s762706872 | p02243 | u007270338 | 1530999477 | Python | Python3 | py | Runtime Error | 0 | 0 | 1585 | #coding:utf-8
import numpy as np
n = int(input())
inf = 1000000000000000
def minHeapify(Q,i):
H = len(Q)
l = 2*i
r = 2*i + 1
if l < H and Q[l][1] < Q[i][1]:
smallest = l
else:
smallest = i
if r < H and Q[r][1] < Q[smallest][1]:
smallest = r
if smallest != i:
... |
s843155929 | p02243 | u684241248 | 1531715759 | Python | Python3 | py | Runtime Error | 0 | 0 | 4593 | # -*- coding: utf-8 -*-
from collections import defaultdict
from heapq import heappop, heappush
def dijkstra(edges, start, *, adj_matrix=False, default_value=float('inf')):
'''
Returns best costs to each node from 'start' node in the given graph.
(Single Source Shortest Path - SSSP)
If edges is given... |
s176385792 | p02243 | u567380442 | 1422449899 | Python | Python3 | py | Runtime Error | 600 | 7172 | 519 | import io, sys, itertools
f = sys.stdin
def take2(iterable):
i = iter(iterable)
while True:
yield next(i), next(i)
n = int(f.readline())
adj =[[(v, c) for v, c in take2(map(int, f.readline().split()[2:]))] for _ in range(n)]
d = [100000 * 100 + 1] * n
d[0] = 0
def search(parent, children):
... |
s741918244 | p02243 | u177808190 | 1455082265 | Python | Python | py | Runtime Error | 10 | 6488 | 901 | MAX = 100
INF = 1000000
WHITE = 0
GRAY = 1
BLACK = 2
n = int(raw_input())
M = [[INF for i in range(n)]for j in range(n)]
d = [INF for i in range(MAX)]
Color = [WHITE for i in range(MAX)]
for i in range(n):
tmp = map(int,raw_input().split())
u = tmp[0]
k = tmp[1]
for j in range(1, k + 1):
v = tm... |
s552386463 | p02243 | u138577439 | 1486893329 | Python | Python3 | py | Runtime Error | 0 | 0 | 690 | V=int(input())
G=[[] for i in range(V)]
d=[1001001001 for i in range(V)]
used=[False for i in range(V)]
import heapq
def dijkstra(s):
q=[]
d[s]=0
heapq.heappush(q,(0, s))
while(len(q)):
p=heapq.heappop(q)
v=p[1]
used[v]=true
if d[v]<p[0]:
... |
s922390877 | p02243 | u798803522 | 1511064737 | Python | Python3 | py | Runtime Error | 0 | 0 | 818 | from collections import defaultdict
import heapq
v_num = int(input())
connect = defaultdict(list)
for _ in range(v_num):
que = [int(n) for n in input().split(" ")]
connect[que[0]] = [[v, w] for v, w in zip(que[2:len(que):2], que[3:len(que):2])
# weight_edge[que[0]] = {k:v for k, v in zip(que[2:len(que):2],... |
s017238616 | p02243 | u150984829 | 1520418592 | Python | Python3 | py | Runtime Error | 0 | 0 | 352 | import sys
from heapq import*
e=sys.stdin.readline
I=float("inf")
def m():
n=int(e())
A=[]
for _ in[0]*n:
e=list(map(int,e().split()))
A+=[zip(e[2::2],e[3::2])]
d=[0]+[I]*n
H=[(0,0)]
while H:
u=heappop(H)[1]
for v,c in A[u]:
t=d[u]+c
if d[v]>t:
d[v]=t
heappush(H,(t,v))
print('\n'.join(f'{i}... |
s626456910 | p02243 | u792145349 | 1525228743 | Python | Python3 | py | Runtime Error | 0 | 0 | 1403 | N = int(input())
G = [[] for i in range(N)]
for nod in range(N):
tmp = list(map(int, input().split()))
for i in range(2, tmp[1]*2+1, 2):
edge, cos = tmp[i], tmp[i+1]
G[nod].append([edge, cos])
import heapq
def dijkstra(x):
d = [float('inf')] * N
d[x] = 0
visited = {x}
# d, ... |
s314243013 | p02243 | u126478680 | 1526027537 | Python | Python3 | py | Runtime Error | 30 | 6368 | 1139 | from heapq import heappush, heappop
from enum import Enum, auto
INFTY = float('inf')
class Color(Enum):
WHITE = auto()
GRAY = auto()
BLACK = auto()
n = int(input())
M = [[-1 for i in range(n)] for i in range(n)]
adj_list = []
for i in range(n):
u, k, *kv = list(map(int, input().split(' ')))
if k ... |
s325614994 | p02244 | u726330006 | 1540483492 | Python | Python3 | py | Runtime Error | 30 | 5640 | 2495 |
class Chess_board:
def __init__(self):
self.board=[[0]*8 for i in range(8)]
self.queen_array=[]
self.queen_row=[]
def copy_board(chess_board):
new_board=Chess_board()
new_board.board=[chess_board.board[i][:] for i in range(8)]
new_board.queen_array=chess_board.queen_array[:]
... |
s611336135 | p02244 | u726330006 | 1540483589 | Python | Python3 | py | Runtime Error | 30 | 5640 | 2523 |
class Chess_board:
def __init__(self):
self.board=[[0]*8 for i in range(8)]
self.queen_array=[]
self.queen_row=[]
def copy_board(chess_board):
new_board=Chess_board()
new_board.board=[chess_board.board[i][:] for i in range(8)]
new_board.queen_array=chess_board.queen_array[:]
... |
s941291079 | p02244 | u408260374 | 1456536051 | Python | Python3 | py | Runtime Error | 0 | 0 | 521 | import itertools
N, Q, row, col = input(), [], range(8), range(8)
for _ in range(N):
r, c = map(int, raw_input().split())
Q.append((r, c))
row.remove(r)
col.remove(c)
for l in itertools.permutations(col):
queen = Q + list(zip(row, l))
if not any((r1 != r2 or c1 != c2) and (r1 == r2 or c1 == c2 o... |
s562262020 | p02244 | u533883485 | 1502107072 | Python | Python3 | py | Runtime Error | 30 | 7920 | 2819 | # coding=utf-8
class Tree():
def __init__(self, init_field):
self.root = init_field
def search(self, field_id, field):
global final_queen_pos
#print("field_id:", field_id)
#field.print_field()
q_r = rest_row[field_id - n]
if final_queen_pos:
return N... |
s000031433 | p02244 | u466299927 | 1523959862 | Python | Python3 | py | Runtime Error | 0 | 0 | 2384 | # -*- coding: utf-8 -*-
import sys
BOARD_SIZE_W = 8
BOARD_SIZE_H = 8
def set_queen(board, queen_point):
"""
クイーンを指定座標に配置した後、残りの配置可能な位置の配列を返す
"""
return filter(create_queen_filter(queen_point), board)
def create_queen_filter(queen_point):
"""
指定位置にクイーンを配置したことにより、対象座標へ配置不可能にならないかを確認する関数を返す
... |
s034453482 | p02244 | u466299927 | 1523959895 | Python | Python3 | py | Runtime Error | 0 | 0 | 2384 | # -*- coding: utf-8 -*-
import sys
BOARD_SIZE_W = 8
BOARD_SIZE_H = 8
def set_queen(board, queen_point):
"""
クイーンを指定座標に配置した後、残りの配置可能な位置の配列を返す
"""
return filter(create_queen_filter(queen_point), board)
def create_queen_filter(queen_point):
"""
指定位置にクイーンを配置したことにより、対象座標へ配置不可能にならないかを確認する関数を返す
... |
s364185102 | p02244 | u466299927 | 1523959964 | Python | Python3 | py | Runtime Error | 0 | 0 | 2384 | # -*- coding: utf-8 -*-
import sys
BOARD_SIZE_W = 8
BOARD_SIZE_H = 8
def set_queen(board, queen_point):
"""
クイーンを指定座標に配置した後、残りの配置可能な位置の配列を返す
"""
return filter(create_queen_filter(queen_point), board)
def create_queen_filter(queen_point):
"""
指定位置にクイーンを配置したことにより、対象座標へ配置不可能にならないかを確認する関数を返す
... |
s648388685 | p02244 | u466299927 | 1523961855 | Python | Python3 | py | Runtime Error | 20 | 5628 | 2435 | # -*- coding: utf-8 -*-
import sys
BOARD_SIZE_W = 8
BOARD_SIZE_H = 8
def set_queen(board, queen_point):
"""
クイーンを指定座標に配置した後、残りの配置可能な位置の配列を返す
"""
return filter(create_queen_filter(queen_point), board)
def create_queen_filter(queen_point):
"""
指定位置にクイーンを配置したことにより、対象座標へ配置不可能にならないかを確認する関数を返す
... |
s962900907 | p02244 | u466299927 | 1523961972 | Python | Python3 | py | Runtime Error | 20 | 5628 | 2435 | # -*- coding: utf-8 -*-
import sys
BOARD_SIZE_W = 8
BOARD_SIZE_H = 8
def set_queen(board, queen_point):
"""
クイーンを指定座標に配置した後、残りの配置可能な位置の配列を返す
"""
return filter(create_queen_filter(queen_point), board)
def create_queen_filter(queen_point):
"""
指定位置にクイーンを配置したことにより、対象座標へ配置不可能にならないかを確認する関数を返す
... |
s336920426 | p02244 | u466299927 | 1523962368 | Python | Python3 | py | Runtime Error | 20 | 5628 | 2453 | # -*- coding: utf-8 -*-
import sys
BOARD_SIZE_W = 8
BOARD_SIZE_H = 8
def set_queen(board, queen_point):
"""
クイーンを指定座標に配置した後、残りの配置可能な位置の配列を返す
"""
return filter(create_queen_filter(queen_point), board)
def create_queen_filter(queen_point):
"""
指定位置にクイーンを配置したことにより、対象座標へ配置不可能にならないかを確認する関数を返す
... |
s718582803 | p02244 | u825008385 | 1526255091 | Python | Python3 | py | Runtime Error | 0 | 0 | 5309 | # 8 Puzzle
import copy
z = 0
[N, d] = [3, 0]
check_flag = [[1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4],
[2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1],
[3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2],
[4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3],
[3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4],
... |
s728374083 | p02244 | u138546245 | 1526779475 | Python | Python3 | py | Runtime Error | 0 | 0 | 2100 | from copy import deepcopy
class EightQueen:
NQUEENS = 8
SIZE = 8
class Board:
def __init__(self, size):
self.queens = []
self.size = size
def place(self, i, j):
self.queens.append((i, j))
def count(self):
return len(self.queens)
... |
s088353908 | p02245 | u800534567 | 1545537640 | Python | Python3 | py | Runtime Error | 0 | 0 | 2347 | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
typedef char Board[10];
Board ini_board, board;
const Board target = "123456780";
Board *history;
int nhistories=0;
typedef enum { U, D, L, R } Direction;
typedef struct {
int pos;
Direction dir;
} Motion;
int minstep = INT_MAX;
co... |
s636136411 | p02245 | u800534567 | 1545546390 | Python | Python3 | py | Runtime Error | 0 | 0 | 2311 | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
typedef char Board[10];
Board ini_board, board;
const Board target = "123456780";
Board *history;
int nhistories=0;
typedef enum { U, D, L, R } Direction;
typedef struct {
int pos;
Direction dir;
} Motion;
int minstep = 50;
const M... |
s340273741 | p02245 | u800534567 | 1545632670 | Python | Python3 | py | Runtime Error | 0 | 0 | 818 | import sys
import queue
N = 3
f= ''.join(sys.stdin.readline().split())
f+= ''.join(sys.stdin.readline().split())
f+= ''.join(sys.stdin.readline().split())
dd = [[-1, 0], [0, -1], [1, 0], [0, 1]]
Q = queue.Queue()
V = dict()
Q.put([f,f.index('0'),0])
V[f] = True
while not Q.empty():
u = Q.get()
if u[0] == '... |
s432588145 | p02245 | u800534567 | 1545632682 | Python | Python3 | py | Runtime Error | 0 | 0 | 818 | import sys
import queue
N = 3
f= ''.join(sys.stdin.readline().split())
f+= ''.join(sys.stdin.readline().split())
f+= ''.join(sys.stdin.readline().split())
dd = [[-1, 0], [0, -1], [1, 0], [0, 1]]
Q = queue.Queue()
V = dict()
Q.put([f,f.index('0'),0])
V[f] = True
while not Q.empty():
u = Q.get()
if u[0] == '... |
s931781703 | p02245 | u800534567 | 1545632778 | Python | Python3 | py | Runtime Error | 0 | 0 | 817 | import sys
import queue
N = 3
f= ''.join(sys.stdin.readline().split())
f+= ''.join(sys.stdin.readline().split())
f+= ''.join(sys.stdin.readline().split())
dd = [[-1, 0], [0, -1], [1, 0], [0, 1]]
Q = queue.Queue()
V = dict()
Q.put([f,f.index('0'),0])
V[f] = True
while not Q.empty():
u = Q.get()
if u[0] == '... |
s905547687 | p02245 | u800534567 | 1545651683 | Python | Python3 | py | Runtime Error | 0 | 0 | 2557 | #include <stdlib.h>
#include <string.h>
typedef char Board[10];
Board ini_board, board, *history;
const Board target = "123456780";
int nhistories=0;
typedef enum { U, D, L, R } Direction;
typedef struct {
char pos;
char dir;
} Motion;
int minstep;
const Motion motion[9][5] =
{{{1,L},{3,U},{-1}}, {{0,R},{2,L... |
s388193086 | p02245 | u800534567 | 1545651709 | Python | Python3 | py | Runtime Error | 0 | 0 | 2576 | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef char Board[10];
Board ini_board, board, *history;
const Board target = "123456780";
int nhistories=0;
typedef enum { U, D, L, R } Direction;
typedef struct {
char pos;
char dir;
} Motion;
int minstep;
const Motion motion[9][5] =
{{{1,L},{3,U}... |
s339241182 | p02245 | u800534567 | 1545797180 | Python | Python3 | py | Runtime Error | 0 | 0 | 1944 | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
unsigned int b;
char step;
} Board;
int qlen=32202;
typedef enum { U, D, L, R } Direction;
typedef struct {
int pos;
Direction dir;
} Motion;
const Motion motion[9][5] =
{{{1,L},{3,U},{-1}}, {{0,R},{2,L},{4,U},{-1}}, {{1,R},{5,U}... |
s872201964 | p02245 | u797673668 | 1455093407 | Python | Python3 | py | Runtime Error | 880 | 24560 | 1010 | import heapq
from itertools import chain
from operator import mul
exp10 = [10 ** a for a in range(8, -1, -1)]
movables = [{1, 3}, {0, 2, 4}, {1, 5}, {0, 4, 6}, {1, 3, 5, 7}, {2, 4, 8}, {3, 7}, {4, 6, 8}, {5, 7}]
destination = 123456780
def swap(board, move_from, move_to):
return board + (exp10[move_to] - exp10[... |
s183831576 | p02245 | u024715419 | 1513043488 | Python | Python3 | py | Runtime Error | 0 | 0 | 2415 | import heapq
def d_manhattan(node_list):
s = 0
for i in range(9):
x_goal = i%3
y_goal = i//3
x_now = (node_list[i] - 1)%3
y_now = (node_list[i] - 1)//3
if y_now == -1:
y_now = 2
dx = abs(x_now - x_goal)
dy = abs(y_now - y_goal)
s += dx... |
s837433173 | p02245 | u024715419 | 1513043549 | Python | Python3 | py | Runtime Error | 0 | 0 | 2415 | import heapq
def d_manhattan(node_list):
s = 0
for i in range(9):
x_goal = i%3
y_goal = i//3
x_now = (node_list[i] - 1)%3
y_now = (node_list[i] - 1)//3
if y_now == -1:
y_now = 2
dx = abs(x_now - x_goal)
dy = abs(y_now - y_goal)
s += dx... |
s240908239 | p02245 | u426534722 | 1519743939 | Python | Python3 | py | Runtime Error | 0 | 0 | 818 | from collections import deque
dy = [-1, 0, 0, 1]
dx = [0, -1, 1, 0]
def g(i, j, a):
t = a // (10 ** j) % 10
return a - t * (10 ** j) + t * (10 ** i)
def MAIN():
m = {8:{7, 5}, 7:{8, 6, 4}, 6:{7, 3}, 5:{8, 4, 2}, 4:{7, 5, 3, 1}, 3:{6, 4, 0}, 2:{5, 1}, 1:{4, 2, 0}, 0:{3, 1}}
MAP = "".join(input().replace(... |
s905230411 | p02245 | u620516796 | 1524439520 | Python | Python3 | py | Runtime Error | 0 | 0 | 5981 | import time
import math
class Node:
def __init__(self, board, parent, fValue, depth):
self.board = board
self.parent = parent
self.fValue = fValue
self.depth = depth
def __eq__(self, other):
return self.board == other.board
def __lt__(self, other):
return s... |
s096609557 | p02245 | u620516796 | 1524439631 | Python | Python3 | py | Runtime Error | 0 | 0 | 4757 | import time import math class Node: def __init__(self, board, parent, fValue, depth): self.board = board self.parent = parent self.fValue = fValue self.depth = depth def __eq__(self, other): return self.board == other.board def __lt__(self, other): return self.fValue < other.fValue def __hash__(self): return hash(self.... |
s990822004 | p02245 | u167493070 | 1525758807 | Python | Python3 | py | Runtime Error | 0 | 0 | 2707 | import sys;
import heapq
def iterative(i,j):
q = []
heapq.heappush(q,(simpleHS(swap_puz),0,i,j,0,puz))
global finding
while len(q):
items = heapq.heappop(q)
c_dWithH = items[0]
c_depth = items[1]
_i = items[2]
_j = items[3]
prev_move = items[4]
c... |
s827927569 | p02245 | u167493070 | 1525758855 | Python | Python3 | py | Runtime Error | 0 | 0 | 2707 | import sys;
import heapq
def iterative(i,j):
q = []
heapq.heappush(q,(simpleHS(swap_puz),0,i,j,0,puz))
global finding
while len(q):
items = heapq.heappop(q)
c_dWithH = items[0]
c_depth = items[1]
_i = items[2]
_j = items[3]
prev_move = items[4]
c... |
s143795036 | p02245 | u167493070 | 1525930062 | Python | Python3 | py | Runtime Error | 0 | 0 | 2934 | import sys;
import heapq
def iterative(i,j):
q = []
q.append(sumcost,(0,i,j,0,puz))
global finding
while len(q):
c_dWithH, items = q.pop(0)
c_depth = items[0]
_i = items[1]
_j = items[2]
prev_move = items[3]
c_puz = items[4]
_sum_cost = c_dWithH ... |
s197574275 | p02245 | u167493070 | 1525930113 | Python | Python3 | py | Runtime Error | 0 | 0 | 2924 | import sys;
import heapq
def iterative(i,j):
q = []
q.append(sumcost,0,i,j,0,puz)
global finding
while len(q):
c_dWithH, items = q.pop(0)
c_depth = items[0]
_i = items[1]
_j = items[2]
prev_move = items[3]
c_puz = items[4]
_sum_cost = c_dWithH - ... |
s994647825 | p02245 | u126478680 | 1527245213 | Python | Python3 | py | Runtime Error | 0 | 0 | 1735 | class Puzzle:
def __init__(self, field=None, path=''):
self.f = field
self.space = None
for i in range(9):
if self.f[i] == 9:
self.space = i
self.path = path
def __lt__(self, pzl): # <
for i in range(9):
if self.f[i] == pzl.f[i]:
... |
s801314313 | p02245 | u126478680 | 1527245297 | Python | Python3 | py | Runtime Error | 0 | 0 | 1736 | class Puzzle:
def __init__(self, field=None, path=''):
self.f = field
self.space = None
for i in range(9):
if self.f[i] == 9:
self.space = i
self.path = path
def __lt__(self, pzl): # <
for i in range(9):
if self.f[i] == pzl.f[i]:
... |
s566803662 | p02245 | u126478680 | 1527245328 | Python | Python3 | py | Runtime Error | 2370 | 31540 | 1780 | from collections import deque, OrderedDict
class Puzzle:
def __init__(self, field=None, path=''):
self.f = field
self.space = None
for i in range(9):
if self.f[i] == 9:
self.space = i
self.path = path
def __lt__(self, pzl): # <
for i in range... |
s761681232 | p02246 | u279605379 | 1534989547 | Python | Python3 | py | Runtime Error | 0 | 0 | 1155 | from collections import deque
def move(P):
for i in range(4):
for j in range(4):
if P[i][j] == 0:
r,c = i,j
if not r == 0:
tmp = [i[:] for i in P]
tmp[r][c],tmp[r-1][c] = tmp[r-1][c],tmp[r][c]
yield tmp
if not r == 3:
tmp = [i[:] for i in P... |
s369327377 | p02246 | u279605379 | 1534989570 | Python | Python3 | py | Runtime Error | 0 | 0 | 1155 | from collections import deque
def move(P):
for i in range(4):
for j in range(4):
if P[i][j] == 0:
r,c = i,j
if not r == 0:
tmp = [i[:] for i in P]
tmp[r][c],tmp[r-1][c] = tmp[r-1][c],tmp[r][c]
yield tmp
if not r == 3:
tmp = [i[:] for i in P... |
s669579406 | p02246 | u279605379 | 1535079864 | Python | Python3 | py | Runtime Error | 30 | 6024 | 1990 | from collections import deque
import heapq
def move(P,p):
if p > 3:
tmp = P[:]
tmp[p],tmp[p-4] = tmp[p-4],tmp[p]
tmpp = p - 4
yield tmp,tmpp
if p < 12:
tmp = P[:]
tmp[p],tmp[p+4] = tmp[p+4],tmp[p]
tmpp = p + 4
yield tmp,tmpp
if p%4 > 0:
... |
s727053752 | p02246 | u279605379 | 1535131337 | Python | Python3 | py | Runtime Error | 0 | 0 | 1289 | from collections import deque
def move(P):
if not r == 0:
tmp = [[i for i in j] for j in P]
tmp[r][c],tmp[r-1][c] = tmp[r-1][c],tmp[r][c]
yield tmp
if not r == 3:
tmp = [[i for i in j] for j in P]
tmp[r][c],tmp[r+1][c] = tmp[r+1][c],tmp[r][c]
yield tmp
if not... |
s988986790 | p02246 | u279605379 | 1535132235 | Python | Python3 | py | Runtime Error | 0 | 0 | 1673 | #双方向 両方 deque
from collections import deque
def move(P,p):
if p > 3:
tmp = P[:]
tmp[p],tmp[p-4] = tmp[p-4],tmp[p]
tmpp = p - 4
yield tmp,tmpp
if p < 12:
tmp = P[:]
tmp[p],tmp[p+4] = tmp[p+4],tmp[p]
tmpp = p + 4
yield tmp,tmpp
if p%4 > 0:
... |
s330379820 | p02246 | u279605379 | 1535316095 | Python | Python3 | py | Runtime Error | 30 | 6020 | 1789 | from collections import deque
import heapq
def move(P,p):
if p > 3:
tmp = P[:]
tmp[p],tmp[p-4] = tmp[p-4],tmp[p]
tmpp = p - 4
yield tmp,tmpp
if p < 12:
tmp = P[:]
tmp[p],tmp[p+4] = tmp[p+4],tmp[p]
tmpp = p + 4
yield tmp,tmpp
if p%4 > 0:
... |
s842807746 | p02246 | u279605379 | 1535316415 | Python | Python3 | py | Runtime Error | 0 | 0 | 1794 | from collections import deque
import heapq
def move(P,p):
if p > 3:
tmp = P[:]
tmp[p],tmp[p-4] = tmp[p-4],tmp[p]
tmpp = p - 4
yield tmp,tmpp
if p < 12:
tmp = P[:]
tmp[p],tmp[p+4] = tmp[p+4],tmp[p]
tmpp = p + 4
yield tmp,tmpp
if p%4 > 0:
... |
s392459118 | p02246 | u800534567 | 1545978306 | Python | Python3 | py | Runtime Error | 0 | 0 | 2322 | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 4
#define N2 16
#define LIMIT 80
typedef struct {
int b[N2+1];
} Board;
Board board;
int minstep;
typedef enum { R, U, L, D } Direction;
typedef struct { int pos; Direction dir; } Motion;
// 0 1 2 3
// 4 5 6 7
// 8 9 10 11
// 12 13 14 1... |
s181272594 | p02246 | u567380442 | 1422512049 | Python | Python3 | py | Runtime Error | 0 | 0 | 1017 | import sys, itertools
f = sys.stdin
start = [line.split() for line in f]
start = tuple(int(x) for y in start for x in y)
end =(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0)
def next_board(b):
brank = b.index(0)
if brank % 4:
yield b[:brank - 1] + (b[brank], b[brank - 1]) + b[brank + 1:]
if... |
s276618943 | p02246 | u567380442 | 1422512513 | Python | Python3 | py | Runtime Error | 0 | 0 | 949 | start = [input().split() for _ in range(4)]
start = tuple(int(x) for y in start for x in y)
end =(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0)
def next_board(b):
brank = b.index(0)
if brank % 4:
yield b[:brank - 1] + (b[brank], b[brank - 1]) + b[brank + 1:]
if brank // 4:
yield b[:... |
s349199998 | p02246 | u567380442 | 1422514440 | Python | Python3 | py | Runtime Error | 0 | 0 | 1117 | start = [input().split() for _ in range(4)]
start = [x for y in start for x in y]
start[start.index('10')] = 'a'
start[start.index('11')] = 'b'
start[start.index('12')] = 'c'
start[start.index('13')] = 'd'
start[start.index('14')] = 'e'
start[start.index('15')] = 'f'
start = ''.join(start)
end = '123456789abcdef0'
de... |
s567785894 | p02246 | u567380442 | 1422515849 | Python | Python3 | py | Runtime Error | 0 | 0 | 1014 | import sys
start = [line.split() for line in sys.stdin]
start = [x for y in start for x in y]
start[start.index('10')] = 'a'
start[start.index('11')] = 'b'
start[start.index('12')] = 'c'
start[start.index('13')] = 'd'
start[start.index('14')] = 'e'
start[start.index('15')] = 'f'
start = ''.join(start)
end = '123456789... |
s980415940 | p02246 | u567380442 | 1422515901 | Python | Python3 | py | Runtime Error | 0 | 0 | 1026 | import sys
start = [sys.stdin.readline().split() for _ in range(4)]
start = [x for y in start for x in y]
start[start.index('10')] = 'a'
start[start.index('11')] = 'b'
start[start.index('12')] = 'c'
start[start.index('13')] = 'd'
start[start.index('14')] = 'e'
start[start.index('15')] = 'f'
start = ''.join(start)
end ... |
s479692298 | p02246 | u567380442 | 1422515967 | Python | Python3 | py | Runtime Error | 0 | 0 | 1002 | start = [input().split() for _ in range(4)]
start = [x for y in start for x in y]
start[start.index('10')] = 'a'
start[start.index('11')] = 'b'
start[start.index('12')] = 'c'
start[start.index('13')] = 'd'
start[start.index('14')] = 'e'
start[start.index('15')] = 'f'
start = ''.join(start)
end = '123456789abcdef0'
de... |
s769319531 | p02246 | u603049633 | 1496637891 | Python | Python3 | py | Runtime Error | 14680 | 8724 | 2025 | import queue
adjacent=(
(1,4),
(0,2,5),
(1,3,6),
(2,7),
(0,5,8),
(1,4,6,9),
(2,5,7,10),
(3,6,11),
(4,9,12),
(5,8,10,13),
(6,9,11,14),
(7,10,15),
(8,13),
(9,12,14),
(10,13,15),
(11,14),
)
distance = (
(),
(0,1,2,3,1,2,3,4,2,3,4,5,3,4,5,6),
(1... |
s814974094 | p02246 | u426534722 | 1500493721 | Python | Python3 | py | Runtime Error | 0 | 0 | 2236 | from sys import stdin
import copy
dx = tuple(1,0,-1,0)
dy = tuple(0,1,0,-1)
dir = "ruld"
N = 4
N2 = 16
LIMIT = 50
MDT = ((0,1,2,3,1,2,3,4,2,3,4,5,3,4,5,6),
(1,0,1,2,2,1,2,3,3,2,3,4,4,3,4,5),
(2,1,0,1,3,2,1,2,4,3,2,3,5,4,3,4),
(3,2,1,0,4,3,2,1,5,4,3,2,6,5,4,3),
(1,2,3,4,0,1,2,3,1,2,3,4,2,... |
s749444236 | p02246 | u426534722 | 1500493748 | Python | Python3 | py | Runtime Error | 0 | 0 | 2236 | from sys import stdin
import copy
dx = tuple(1,0,-1,0)
dy = tuple(0,1,0,-1)
dir = "ruld"
N = 4
N2 = 16
LIMIT = 50
MDT = ((0,1,2,3,1,2,3,4,2,3,4,5,3,4,5,6),
(1,0,1,2,2,1,2,3,3,2,3,4,4,3,4,5),
(2,1,0,1,3,2,1,2,4,3,2,3,5,4,3,4),
(3,2,1,0,4,3,2,1,5,4,3,2,6,5,4,3),
(1,2,3,4,0,1,2,3,1,2,3,4,2,... |
s238468349 | p02246 | u798803522 | 1510414925 | Python | Python3 | py | Runtime Error | 0 | 0 | 2206 | import copy
import heapq as hq
WIDTH = 4
def hashnum(state):
num = ""
for i in range(WIDTH):
for j in range(WIDTH):
num += str(state[i][j])
return num
def heauristic(here_x, here_y):
return abs((WIDTH - 1) - here_x) + abs((WIDTH - 1) - here_y)
ini_state = []
for i in range(WIDTH):
... |
s515115311 | p02246 | u024715419 | 1513043906 | Python | Python3 | py | Runtime Error | 0 | 0 | 2433 | import heapq
def d_manhattan(node_list):
s = 0
for i in range(15):
x_goal = i%4
y_goal = i//4
x_now = (node_list[i] - 1)%4
y_now = (node_list[i] - 1)//4
if y_now == -1:
y_now = 3
dx = abs(x_now - x_goal)
dy = abs(y_now - y_goal)
s += d... |
s655613039 | p02246 | u024715419 | 1513044018 | Python | Python3 | py | Runtime Error | 0 | 0 | 2433 | import heapq
def d_manhattan(node_list):
s = 0
for i in range(15):
x_goal = i%4
y_goal = i//4
x_now = (node_list[i] - 1)%4
y_now = (node_list[i] - 1)//4
if y_now == -1:
y_now = 3
dx = abs(x_now - x_goal)
dy = abs(y_now - y_goal)
s += d... |
s134551337 | p02246 | u859725751 | 1516588519 | Python | Python3 | py | Runtime Error | 0 | 0 | 124 | x = input()
n = int(input())
for i in range(n):
y = input()
if y in x:
print(1)
else:
print(0)
|
s400927142 | p02246 | u859725751 | 1516588548 | Python | Python3 | py | Runtime Error | 0 | 0 | 124 | x = input()
n = int(input())
for i in range(n):
y = input()
if y in x:
print(1)
else:
print(0)
|
s943403429 | p02246 | u859725751 | 1516588556 | Python | Python | py | Runtime Error | 0 | 0 | 124 | x = input()
n = int(input())
for i in range(n):
y = input()
if y in x:
print(1)
else:
print(0)
|
s764038789 | p02246 | u859725751 | 1516588586 | Python | Python3 | py | Runtime Error | 0 | 0 | 124 | x = input()
n = int(input())
for i in range(n):
y = input()
if y in x:
print(1)
else:
print(0)
|
s914565948 | p02246 | u859725751 | 1516588604 | Python | Python3 | py | Runtime Error | 0 | 0 | 133 | x = input()
n = int(input())
print(n)
for i in range(n):
y = input()
if y in x:
print(1)
else:
print(0)
|
s991464103 | p02246 | u859725751 | 1516588624 | Python | Python3 | py | Runtime Error | 0 | 0 | 124 | x = input()
n = int(input())
for i in range(n):
y = input()
if y in x:
print(1)
else:
print(0)
|
s663044802 | p02246 | u426534722 | 1519922325 | Python | Python3 | py | Runtime Error | 0 | 0 | 1009 | from heapq import heapify, heappush, heappop
N = 4
m = {0: {1, 4}, 1: {0, 2, 5}, 2: {1, 3, 6}, 3: {2, 7},
4: {0, 5, 8}, 5: {1, 4, 6, 9}, 6: {2, 5, 7, 10}, 7: {3, 6, 11},
8: {4, 9, 12}, 9: {5, 8, 10, 13}, 10: {6, 9, 11, 14}, 11: {7, 10, 15},
12: {8, 13}, 13: {9, 12, 14}, 14: {10, 13, 15}, 15: {11, 14}}
go... |
s713710975 | p02246 | u167493070 | 1526272342 | Python | Python3 | py | Runtime Error | 30 | 6064 | 3915 | import sys;
import heapq
from collections import deque
def iterative(i,j):
q = deque()
q.append((sumcost,0,i,j,0,puz))
global finding
while len(q):
items = q.pop()
cost = items[0]
if(cost > depth):
continue
c_depth = items[1]
_i = items[2]
... |
s087145643 | p02247 | u726330006 | 1540808782 | Python | Python3 | py | Runtime Error | 20 | 5576 | 1080 | text=input()
string=input()
#common_length[i]は、探索列がstring[i]で探索を終了したときに、
# string[i-common_lneght[i] + 1] 〜string[i]で構成される文字列が、探索価値を持つことを示す
len_string=len(string)
common_length=[0]*len_string
tmp=0
tmp_tmp=0
for i in range(1,len_string):
if(string[i]==string[tmp]):
tmp_tmp=tmp
while(string[i]==s... |
s754806796 | p02247 | u800534567 | 1546040599 | Python | Python3 | py | Runtime Error | 0 | 0 | 500 | #include <stdio.h>
#include <string.h>
int main()
{
int i, j;
char t[1002], p[1002];
fgets(t, 1001, stdin);
fgets(p, 1001, stdin);
if (t[strlen(t)-1]=='\n') t[strlen(t)-1]='\0';
if (p[strlen(p)-1]=='\n') p[strlen(p)-1]='\0';
int plen = strlen(p);
if (plen>strlen(t)) return 0;
for (i=0; i<strlen(t)-s... |
s126036137 | p02247 | u078042885 | 1486709654 | Python | Python3 | py | Runtime Error | 0 | 0 | 78 | t=input();p=input()
for i in range(len(t)):
if t[i:].startwith(p):print(i) |
s174337626 | p02247 | u603049633 | 1496647221 | Python | Python3 | py | Runtime Error | 0 | 0 | 94 | t=input()
p=input()
lt=len(t)
lp=len(p)
for i in range(lt-lp+1):
if t[i:i+l_p]==p:print(i) |
s513399547 | p02248 | u318430977 | 1531931130 | Python | Python3 | py | Runtime Error | 20 | 5564 | 491 | def rabin_karp(T, P, d, q):
n = len(T)
m = len(P)
h = pow(d, m - 1) % q
p = 0
t0 = 0
for i in range(m):
p = (d * p + P[i]) % q
t0 = (d * t0 + T[i]) % q
for s in range(n - m + 1):
if p == t0:
if P[0:(m - 1)] == T[s:(s + m - 1)]:
print(s)
... |
s006823745 | p02248 | u726330006 | 1540810396 | Python | Python3 | py | Runtime Error | 0 | 0 | 1134 | text=input()
string=input()
#common_length[i]は、探索列がstring[i]で探索を終了したときに、
# string[i-common_lneght[i] + 1] 〜string[i]で構成される文字列が、探索価値を持つことを示す
len_string=len(string)
common_length=[0]*len_string
tmp=0
tmp_tmp=0
for i in range(1,len_string):
if(string[i]==string[tmp]):
tmp_tmp=tmp
while(string[i]==... |
s696033495 | p02248 | u798803522 | 1511458410 | Python | Python3 | py | Runtime Error | 30 | 7880 | 3767 | ## SA-IS
from collections import defaultdict
def l_or_s_classification(target):
length = len(target)
l_or_s = ["" for n in range(length)]
for i in range(length):
if i == length - 1 or target[i] < target[i + 1]:
l_or_s[i] = "S"
else:
l_or_s[i] = "L"
return l_or_s... |
s686962000 | p02248 | u798803522 | 1511458492 | Python | Python3 | py | Runtime Error | 30 | 7904 | 3849 | ## SA-IS
from collections import defaultdict
def l_or_s_classification(target):
length = len(target)
l_or_s = ["" for n in range(length)]
for i in range(length):
if i == length - 1 or target[i] < target[i + 1]:
l_or_s[i] = "S"
else:
l_or_s[i] = "L"
return l_or_s... |
s368067303 | p02248 | u798803522 | 1511459371 | Python | Python3 | py | Runtime Error | 50 | 7876 | 3849 | ## SA-IS
from collections import defaultdict
def l_or_s_classification(target):
length = len(target)
l_or_s = ["" for n in range(length)]
for i in range(length):
if i == length - 1 or target[i] < target[i + 1]:
l_or_s[i] = "S"
else:
l_or_s[i] = "L"
return l_or_s... |
s485985739 | p02248 | u426534722 | 1520179144 | Python | Python3 | py | Runtime Error | 0 | 0 | 824 | def kmpTable(w):
lw = len(w)
nx = [-1] * (lw + 1)
j = -1
for i in xrange(lw):
while j >= 0 and w[i] != w[j]:
j = nx[j]
j += 1
nx[i + 1] = j
return nx
def kmpSearch(s, w):
ls = len(s)
start = 0
w_idx = 0
ret = []
nx = kmpTable(w)
while sta... |
s664245220 | p02248 | u426534722 | 1520179170 | Python | Python3 | py | Runtime Error | 0 | 0 | 816 | def kmpTable(w):
lw = len(w)
nx = [-1] * (lw + 1)
j = -1
for i in xrange(lw):
while j >= 0 and w[i] != w[j]:
j = nx[j]
j += 1
nx[i + 1] = j
return nx
def kmpSearch(s, w):
ls = len(s)
start = 0
w_idx = 0
ret = []
nx = kmpTable(w)
while sta... |
s366943866 | p02248 | u150984829 | 1524900520 | Python | Python3 | py | Runtime Error | 0 | 0 | 102 | def f(T,P):for i in range(len(T)):P!=T[i:i+len(P)]or print(i)
if'__main__'__name__:f(input(),input())
|
s707681381 | p02248 | u150984829 | 1524900543 | Python | Python3 | py | Runtime Error | 0 | 0 | 104 | def f(T,P):
for i in range(len(T)):P!=T[i:i+len(P)]or print(i)
if'__main__'__name__:f(input(),input())
|
s635553627 | p02248 | u138546245 | 1527127748 | Python | Python3 | py | Runtime Error | 0 | 0 | 304 | def search_by_dict(s1, s2):
d = defaultdict(list)
for i in range(len(s1)-len(s2)):
d[s1[i:i+len(s2)]].append(i)
return (i for i in d[s2])
def run():
s1 = input()
s2 = input()
for idx in search_by_dict(s1, s2):
print(idx)
if __name__ == '__main__':
run()
|
s895112503 | p02248 | u138546245 | 1527147783 | Python | Python3 | py | Runtime Error | 20 | 5572 | 1259 |
class RKSearch:
shift = 40
size = 33554393
def __init__(self, s1, s2):
self.haystack = self.encode(s1)
self.needle = self.encode(s2)
def find(self):
m, n = len(self.haystack), len(self.needle)
h1 = self.hash(self.haystack, n)
h2 = self.hash(self.needle, n)
... |
s353556458 | p02249 | u726330006 | 1540913909 | Python | Python3 | py | Runtime Error | 20 | 5640 | 3106 | def get_common(string,len_string):
common_length=[0]*len_string
tmp=0
tmp_tmp=0
for i in range(1,len_string):
if(string[i]==string[tmp]):
tmp_tmp=tmp
while(string[i]==string[tmp_tmp] and tmp_tmp >0):
tmp_tmp=common_length[max([tmp_tmp-1,0])]
co... |
s623033506 | p02249 | u831244171 | 1487579317 | Python | Python3 | py | Runtime Error | 30 | 7660 | 696 | H, W = map(int,input().split())
A = []
for i in range(H):
A.append(input())
R, C = map(int,input().split())
B = []
for i in range(R):
B.append(input())
b = B[0]
b_for_move = [0 for i in range(len(B))]
for i in range(len(b)):
for j in range(0,len(b)-i)[::-1]:
if b[i:i+j] == b[len(b)-j-1:len(... |
s149377228 | p02249 | u831244171 | 1487579651 | Python | Python3 | py | Runtime Error | 20 | 7728 | 712 | H, W = map(int,input().split())
A = []
for i in range(H):
A.append(input())
R, C = map(int,input().split())
B = []
for i in range(R):
B.append(input())
b = B[0]
b_for_move = [0 for i in range(len(b))]
for i in range(len(b)):
for j in range(0,len(b)-i)[::-1]:
if b[i:i+j] == b[len(b)-j-1:len(b)]:... |
s259544594 | p02249 | u831244171 | 1487675708 | Python | Python3 | py | Runtime Error | 0 | 0 | 1383 | CSIZE = 256
def make_bm_table(pattern,size):
bm_table = [size]*CSIZE
for i in range(size):
dist = size-i-1
charac = pattern[i]
bm_table[ord(charac)] = dist
return bm_table
def bm_search(pattern,buff):
size = R
bm_table = make_bm_table(pattern[0], size)
... |
s971180593 | p02249 | u426534722 | 1520350527 | Python | Python3 | py | Runtime Error | 0 | 0 | 1310 | base1 = 1009
base2 = 1013
mask = (1 << 32) - 1
def calc_hash(f, r, c):
global ph, pw, h
tmp = [[0] * c for _ in range(r)]
dr, dc = r - ph, c - pw
t1 = 1
for _ in range(pw):
t1 = (t1 * base1) & mask
for i in range(r):
e = 0
for j in range(pw):
e = e * base1 + f... |
s181725274 | p02249 | u426534722 | 1520350941 | Python | Python3 | py | Runtime Error | 0 | 0 | 1357 | base1 = 1009
base2 = 1013
mask = (1 << 32) - 1
def calc_hash(f, r, c):
global ph, pw, h
tmp = [[0] * c for _ in range(r)]
dr, dc = r - ph, c - pw
t1 = 1
t1 = (t1 * (base1 ** pw)) & mask
# for _ in range(pw):
# t1 = (t1 * base1) & mask
for i in range(r):
e = 0
for j in ra... |
s485503586 | p02250 | u797673668 | 1455113734 | Python | Python3 | py | Runtime Error | 0 | 0 | 691 | base = 127
mask = (1 << 32) - 1
def calc_hash(f, pl, tl):
dl = tl - pl
tmp = set()
t = 1
for _ in range(pl):
t = (t * base) & mask
e = 0
for i in range(pl):
e = e * base + f[i]
for i in range(dl):
tmp.add(e)
e = (e * base - t * f[i] + f[i + pl]) & mask
... |
s849256173 | p02250 | u797673668 | 1455113767 | Python | Python3 | py | Runtime Error | 20 | 7732 | 702 | base = 127
mask = (1 << 32) - 1
def calc_hash(f, pl, tl):
dl = tl - pl
tmp = set()
t = 1
for _ in range(pl):
t = (t * base) & mask
e = 0
for i in range(pl):
e = e * base + f[i]
for i in range(dl):
tmp.add(e)
e = (e * base - t * f[i] + f[i + pl]) & mask
... |
s326879085 | p02250 | u797673668 | 1455251705 | Python | Python3 | py | Runtime Error | 0 | 0 | 1451 | base = 127
mask = (1 << 32) - 1
def calc_hash(f, pl, tl, with_array):
dl = tl - pl
tmp = []
t = 1
for _ in range(pl):
t = (t * base) & mask
e = 0
for i in range(pl):
e = (e * base + f[i]) & mask
for i in range(dl):
tmp.append(e)
e = (e * base - t * f[i] + f... |
s862746859 | p02250 | u159356473 | 1481789281 | Python | Python3 | py | Runtime Error | 20 | 7644 | 555 | #coding:utf-8
def MSM(T,P):
Tlist=list(T)
Plist=list(P)
ans=0
for i in range(len(Tlist)):
if Tlist[i]==Plist[0]:
ans+=1
for j in range(1,len(Plist)):
if Plist[j]==Tlist[i+j] and i+j<=len(Tlist):
ans+=1
if ans==len(Plist):
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.