Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

縄張り(Territory)

あなたは南北方向にとても長く伸びたたくさんの道路と，東西方向にとても長く伸びたたくさんの道路が交わった形をした街に住んでいる．隣り合う2 つの南北方向の道路の間隔は 1 km である．また，隣り合う 2 つの東西方向の道路の間隔も 1 km である．

この街には市役所が 1 つある．市役所のある交差点を $(0,0)$ と表す．この街の交差点は 2 つの整数 $i, j$ を用いて交差点 $(i, j)$ と表される．すなわち，交差点 $(i, j)$ とは，交差点 $(0,0)$ から東に $i$ km ($i 

ジョイ君の移動経路

入力例 1 において，下図の斜線部分で示された 3 個の区画がジョイ君の縄張りに属する．

入力例1 におけるジョイ君の縄張り

入力例2

12 2
EENWSEEESWWS

出力例2

7

入力例 2 では，散歩が 2 日間に渡り行われる．それぞれの日の移動経路は入力例 1 と同一である．散歩が完了したとき，下図の斜線部分で示された 7 個の区画がジョイ君の縄張りに属する．

入力例2 におけるジョイ君の縄張り

入力例3

7 1
ENNWNNE

出力例3

0

入力例 3 では，ジョイ君の縄張りに属する区画は存在しない．

入力例4

16 5
WSESSSWWWEEENNNW

出力例4

21

第15回 日本情報オリンピック本選 課題   2016 年 2 月 14 日



Sample input:
12 1
EENWSEEESWWS


Sample output:
3

Submission status: Wrong Answer

Solution code:
from multiprocessing import Pool
import multiprocessing as multi
k=int(input().split()[1])-1
p=input()
x=y=d=e=f=g=0
a=[(0,0)]
def q(t):return[(t[0]+i*x,t[1]+i*y)for i in range(1,k+1)]
for s in p:
 if'E'==s:x+=1;g=[g,x][g<x]
 if'N'==s:y+=1;e=[e,y][e<y]
 if'W'==s:x-=1;f=[f,x][f>x]
 if'S'==s:y-=1;d=[d,y][d>y]
 a+=[(x,y)]
if x>0:g+=x*k
else:f+=x*k
if y>0:e+=y*k
else:d+=y*k
p=Pool(multi.cpu_count())
for t in p.map(q,set(a)):a+=t
p.close()
print(a)
s=set(a)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-s]))

Submission status: Wrong Answer

Solution code:
from multiprocessing import *
k=int(input().split()[1])
p=input()
x=y=0
a=[(0,0)]
def q(i):return[(u+i*x,v+i*y)for u,v in a]
for _ in[0]*k:
 for s in p:
  if'E'==s:x+=1
  if'N'==s:y+=1
  if'W'==s:x-=1
  if'S'==s:y-=1
  a+=[(x,y)]
a=set(a)
with Pool(9)as p:
 for s in p.map(q,range(1,k+1)):a|=set(s)
print(sum([1 for x,y in a if set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])<a]))

Submission status: Wrong Answer

Solution code:
k=int(input().split()[1])
x=y=0
a={(0,0)}
for s in input():
 if'E'==s:x+=1
 if'N'==s:y+=1
 if'W'==s:x-=1
 if'S'==s:y-=1
 a|={(x,y)}
b={(u+x*i,v+y*i)for u,v in a for i in range(1,k)}
print(sum(1 for x,y in b if{(x,y),(x+1,y),(x,y+1),(x+1,y+1)}<b))

Submission status: Wrong Answer

Solution code:
k=int(input().split()[1])
x,y=-1,0
a={}
for s in 'E'+input()*k:
 if s in'EW':x+=[-1,1]['E'==s]
 else:y+=[-1,1]['N'==s]
 for p in[(x,y),(x-1,y),(x-1,y-1),(x,y-1)]:a.setdefault(p,set()).add((x,y))
print(a.values())
print(sum(len(c)>3 for c in a.values()))

Submission status: Wrong Answer

Solution code:
import sys
k=int(input().split()[1])
x,y=-1,0
a={}
for s in'E'+sys.stdin.readline()*k:
 if s in'EW':x+=[-1,1]['E'==s]
 else:y+=[-1,1]['N'==s]
 [a.setdefault(p,set()).add((x,y))for p in[(x,y),(x-1,y),(x-1,y-1),(x,y-1)]]
print(sum(len(c)>3 for c in a.values()))

Submission status: Time Limit Exceeded

Solution code:
area = set()
walk = set()

def route(w, k):
    x = y = 0
    walk.add((0, 0))
    for i in range(0, k):
        for d in w:
            if d == 'E':
                x += 1
            elif d == 'N':
                y += 1
            elif d == 'W':
                x -= 1
            elif d == 'S':
                y -= 1
            walk.add((x, y))
    return walk

def isarea(cx, cy):
    if (cx, cy) in area:
        return
    x1, y1 = cx - 0.5, cy - 0.5
    x2, y2 = cx + 0.5, cy + 0.5
    sq = set([(x1, y1), (x1, y2), (x2, y1), (x2, y2)])
    if sq <= walk:
        area.add((cx, cy))
            
def solve():
    for x, y in walk:
        isarea(x + 0.5, y + 0.5)
        isarea(x - 0.5, y + 0.5)
        isarea(x - 0.5, y - 0.5)
        isarea(x + 0.5, y - 0.5)
    return len(area)

walk = set()
area = set()
line = input()
n, k = map(int, line.split())
w = input()
route(w, k)
print(solve())

Submission status: Time Limit Exceeded

Solution code:
k=int(input().split()[1])
p=input()
x=y=0
a=[(0,0)]
for _ in[0]*k:
 for s in p:
  if'E'==s:x+=1
  if'N'==s:y+=1
  if'W'==s:x-=1
  if'S'==s:y-=1
  a+=[(x,y)]
s=set(a)
m=0
for y in range(min(s,key=lambda y:y[1])[1],max(s,key=lambda y:y[1])[1]):
 for x in range(min(s,key=lambda x:x[0])[0],max(s,key=lambda x:x[0])[0]):
  if len(set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-s)<1:m+=1
print(m)

Submission status: Time Limit Exceeded

Solution code:
k=int(input().split()[1])
p=input()
x=y=d=e=f=g=0
a=[(0,0)]
for _ in[0]*k:
 for s in p:
  if'E'==s:x+=1;g=[g,x][g<x]
  if'N'==s:y+=1;e=[e,y][e<y]
  if'W'==s:x-=1;f=[f,x][f>x]
  if'S'==s:y-=1;d=[d,y][d>y]
  a+=[(x,y)]
s=set(a)
print(sum([1 for y in range(d,e)for x in range(f,g)if len(set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-s)<1]))

Submission status: Time Limit Exceeded

Solution code:
k=int(input().split()[1])
p=input()
x=y=d=e=f=g=0
a=[(0,0)]
for _ in[0]*k:
 for s in p:
  if'E'==s:x+=1;g=[g,x][g<x]
  if'N'==s:y+=1;e=[e,y][e<y]
  if'W'==s:x-=1;f=[f,x][f>x]
  if'S'==s:y-=1;d=[d,y][d>y]
  a+=[(x,y)]
print(sum([1 for y in range(d,e)for x in range(f,g)if all([(x,y)in a,(x+1,y)in a,(x,y+1)in a,(x+1,y+1)in a])]))

Submission status: Time Limit Exceeded

Solution code:
k=int(input().split()[1])
p=input()
x=y=d=e=f=g=0
a=[(0,0)]
for _ in[0]*k:
 for s in p:
  if'E'==s:x+=1;g=[g,x][g<x]
  if'N'==s:y+=1;e=[e,y][e<y]
  if'W'==s:x-=1;f=[f,x][f>x]
  if'S'==s:y-=1;d=[d,y][d>y]
  a+=[(x,y)]
s=set(a)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-s]))

Submission status: Time Limit Exceeded

Solution code:
k=int(input().split()[1])
p=input()
x=y=d=e=f=g=0
a=[(0,0)]
for _ in[0]*k:
 for s in p:
  if s=='E':x+=1;g=[g,x][g<x]
  if s=='N':y+=1;e=[e,y][e<y]
  if s=='W':x-=1;f=[f,x][f>x]
  if s=='S':y-=1;d=[d,y][d>y]
  a+=[(x,y)]
s=set(a)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-s]))

Submission status: Time Limit Exceeded

Solution code:
import collections
k=int(input().split()[1])
p=input()
x=y=d=e=f=g=0
a=collections.deque([(0,0)])
for _ in[0]*k:
 for s in p:
  if'E'==s:x+=1;g=[g,x][g<x]
  if'N'==s:y+=1;e=[e,y][e<y]
  if'W'==s:x-=1;f=[f,x][f>x]
  if'S'==s:y-=1;d=[d,y][d>y]
  a.append((x,y))
s=set(a)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-s]))

Submission status: Time Limit Exceeded

Solution code:
import collections
k=int(input().split()[1])-1
p=input()
x=y=d=e=f=g=0
a=collections.deque([(0,0)])
for s in p:
 if'E'==s:x+=1;g=[g,x][g<x]
 if'N'==s:y+=1;e=[e,y][e<y]
 if'W'==s:x-=1;f=[f,x][f>x]
 if'S'==s:y-=1;d=[d,y][d>y]
 a.append((x,y))
if x>0:g+=x*k
else:f+=x*k
if y>0:e+=y*k
else:d+=y*k
for t in set(a):
 for i in range(1,k+1):
   a.append((t[0]+i*x,t[1]+i*y))
s=set(a)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-s]))

Submission status: Time Limit Exceeded

Solution code:
import collections
k=int(input().split()[1])-1
p=input()
x=y=d=e=f=g=0
a=collections.deque([(0,0)])
for s in p:
 if'E'==s:x+=1;g=[g,x][g<x]
 if'N'==s:y+=1;e=[e,y][e<y]
 if'W'==s:x-=1;f=[f,x][f>x]
 if'S'==s:y-=1;d=[d,y][d>y]
 a.append((x,y))
if x>0:g+=x*k
else:f+=x*k
if y>0:e+=y*k
else:d+=y*k
for t in set(a):
 for i in range(1,k+1):
   a.append((t[0]+i*x,t[1]+i*y))
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-set(a)]))

Submission status: Time Limit Exceeded

Solution code:
import collections
k=int(input().split()[1])-1
p=input()
x=y=d=e=f=g=0
a=collections.deque([(0,0)])
for s in p:
 if'E'==s:x+=1;g=[g,x][g<x]
 if'N'==s:y+=1;e=[e,y][e<y]
 if'W'==s:x-=1;f=[f,x][f>x]
 if'S'==s:y-=1;d=[d,y][d>y]
 a.append((x,y))
if x>0:g+=x*k
else:f+=x*k
if y>0:e+=y*k
else:d+=y*k
[a.append((t[0]+i*x,t[1]+i*y))for t in set(a)for i in range(1,k+1)]
s=set(a)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-s]))

Submission status: Time Limit Exceeded

Solution code:
from collections import *
k=int(input().split()[1])-1
p=input()
x=y=d=e=f=g=0
a=deque([(0,0)])
for s in p:
 if'E'==s:x+=1;g=[g,x][g<x]
 if'N'==s:y+=1;e=[e,y][e<y]
 if'W'==s:x-=1;f=[f,x][f>x]
 if'S'==s:y-=1;d=[d,y][d>y]
 a.append((x,y))
if x>0:g+=x*k
else:f+=x*k
if y>0:e+=y*k
else:d+=y*k
[a.append((t[0]+i*x,t[1]+i*y))for t in set(a)for i in range(1,k+1)]
s=set(a)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-s]))

Submission status: Time Limit Exceeded

Solution code:
k=int(input().split()[1])-1
p=input()
x=y=d=e=f=g=0
a=[(0,0)]
for s in p:
 if'E'==s:x+=1;g=[g,x][g<x]
 if'N'==s:y+=1;e=[e,y][e<y]
 if'W'==s:x-=1;f=[f,x][f>x]
 if'S'==s:y-=1;d=[d,y][d>y]
 a+=[(x,y)]
if x>0:g+=x*k
else:f+=x*k
if y>0:e+=y*k
else:d+=y*k
[a.append((t[0]+i*x,t[1]+i*y))for t in set(a)for i in range(1,k+1)]
s=set(a)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-s]))

Submission status: Time Limit Exceeded

Solution code:
from multiprocessing import Pool
import multiprocessing as multi
k=int(input().split()[1])-1
p=input()
x=y=d=e=f=g=0
a=[(0,0)]
def q(t):return[(t[0]+i*x,t[1]+i*y)for i in range(1,k+1)]
for s in p:
 if'E'==s:x+=1;g=[g,x][g<x]
 if'N'==s:y+=1;e=[e,y][e<y]
 if'W'==s:x-=1;f=[f,x][f>x]
 if'S'==s:y-=1;d=[d,y][d>y]
 a+=[(x,y)]
if x>0:g+=x*k
else:f+=x*k
if y>0:e+=y*k
else:d+=y*k
p=Pool(multi.cpu_count())
for t in p.map(q,set(a)):a+=t
p.close()
s=set(a)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-s]))

Submission status: Time Limit Exceeded

Solution code:
from multiprocessing import Pool
import multiprocessing as multi
k=int(input().split()[1])-1
p=input()
x=y=d=e=f=g=0
a=[(0,0)]
def q(t):return[(t[0]+i*x,t[1]+i*y)for i in range(1,k+1)]
for s in p:
 if'E'==s:x+=1;g=[g,x][g<x]
 if'N'==s:y+=1;e=[e,y][e<y]
 if'W'==s:x-=1;f=[f,x][f>x]
 if'S'==s:y-=1;d=[d,y][d>y]
 a+=[(x,y)]
if x>0:g+=x*k
else:f+=x*k
if y>0:e+=y*k
else:d+=y*k
with Pool(multi.cpu_count())as p:
 for t in p.map(q,set(a)):a+=t
s=set(a)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-s]))

Submission status: Time Limit Exceeded

Solution code:
from multiprocessing import Pool
import multiprocessing as multi
k=int(input().split()[1])-1
p=input()
x=y=d=e=f=g=0
a=[(0,0)]
def q(i):return[(t[0]+i*x,t[1]+i*y)for t in set(a)]
for s in p:
 if'E'==s:x+=1;g=[g,x][g<x]
 if'N'==s:y+=1;e=[e,y][e<y]
 if'W'==s:x-=1;f=[f,x][f>x]
 if'S'==s:y-=1;d=[d,y][d>y]
 a+=[(x,y)]
if x>0:g+=x*k
else:f+=x*k
if y>0:e+=y*k
else:d+=y*k
with Pool(multi.cpu_count())as p:
 for t in p.map(q,range(1,k+1)):a+=t
s=set(a)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-s]))

Submission status: Time Limit Exceeded

Solution code:
from multiprocessing import Pool
import multiprocessing as multi
k=int(input().split()[1])-1
x=y=d=e=f=g=0
a=[(0,0)]
def q(i):return[(u+i*x,v+i*y)for u,v in set(a)]
for s in input():
 if'E'==s:x+=1;g=[g,x][g<x]
 if'N'==s:y+=1;e=[e,y][e<y]
 if'W'==s:x-=1;f=[f,x][f>x]
 if'S'==s:y-=1;d=[d,y][d>y]
 a+=[(x,y)]
if y<0:d+=y*k
else:e+=y*k
if x<0:f+=x*k
else:g+=x*k
with Pool(multi.cpu_count())as p:
 for t in p.map(q,range(1,k+1)):a+=t
s=set(a)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-s]))

Submission status: Time Limit Exceeded

Solution code:
from multiprocessing import Pool
import multiprocessing as multi
k=int(input().split()[1])-1
x=y=d=e=f=g=0
a=[(0,0)]
def q(i):return[(u+i*x,v+i*y)for u,v in a]
for s in input():
 if'E'==s:x+=1;g=[g,x][g<x]
 if'N'==s:y+=1;e=[e,y][e<y]
 if'W'==s:x-=1;f=[f,x][f>x]
 if'S'==s:y-=1;d=[d,y][d>y]
 a+=[(x,y)]
if y<0:d+=y*k
else:e+=y*k
if x<0:f+=x*k
else:g+=x*k
a=set(a)
with Pool(multi.cpu_count())as p:
 for s in p.map(q,range(1,k+1)):a=a|set(s)
s=set(a)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-s]))

Submission status: Time Limit Exceeded

Solution code:
from multiprocessing import Pool
import multiprocessing as multi
k=int(input().split()[1])-1
x=y=d=e=f=g=0
a=[(0,0)]
def q(i):return[(u+i*x,v+i*y)for u,v in a]
for s in input():
 if'E'==s:x+=1;g=[g,x][g<x]
 if'N'==s:y+=1;e=[e,y][e<y]
 if'W'==s:x-=1;f=[f,x][f>x]
 if'S'==s:y-=1;d=[d,y][d>y]
 a+=[(x,y)]
if y<0:d+=y*k
else:e+=y*k
if x<0:f+=x*k
else:g+=x*k
a=set(a)
with Pool(multi.cpu_count())as p:
 for s in p.map(q,range(1,k+1)):a|=set(s)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-a]))

Submission status: Time Limit Exceeded

Solution code:
from multiprocessing import *
k=int(input().split()[1])-1
x=y=d=e=f=g=0
a=[(0,0)]
def q(i):return[(u+i*x,v+i*y)for u,v in a]
for s in input():
 if'E'==s:x+=1;g=[g,x][g<x]
 if'N'==s:y+=1;e=[e,y][e<y]
 if'W'==s:x-=1;f=[f,x][f>x]
 if'S'==s:y-=1;d=[d,y][d>y]
 a+=[(x,y)]
if y<0:d+=y*k
else:e+=y*k
if x<0:f+=x*k
else:g+=x*k
a=set(a)
with Pool(4)as p:
 for s in p.map(q,range(1,k+1)):a|=set(s)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-a]))

Submission status: Time Limit Exceeded

Solution code:
from multiprocessing import *
k=int(input().split()[1])-1
x=y=d=e=f=g=0
a=[(0,0)]
def q(i):return[(u+i*x,v+i*y)for u,v in a]
for s in input():
 if'E'==s:x+=1;g=[g,x][g<x]
 if'N'==s:y+=1;e=[e,y][e<y]
 if'W'==s:x-=1;f=[f,x][f>x]
 if'S'==s:y-=1;d=[d,y][d>y]
 a+=[(x,y)]
if y<0:d+=y*k
else:e+=y*k
if x<0:f+=x*k
else:g+=x*k
a=set(a)
with Pool(10)as p:
 for s in p.map(q,range(1,k+1)):a|=set(s)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-a]))

Submission status: Time Limit Exceeded

Solution code:
from multiprocessing import *
k=int(input().split()[1])-1
x=y=d=e=f=g=0
a=[(0,0)]
def q(i):print(a);return[(u+i*x,v+i*y)for u,v in a]
for s in input():
 if'E'==s:x+=1;g=[g,x][g<x]
 if'N'==s:y+=1;e=[e,y][e<y]
 if'W'==s:x-=1;f=[f,x][f>x]
 if'S'==s:y-=1;d=[d,y][d>y]
 a+=[(x,y)]
if y<0:d+=y*k
else:e+=y*k
if x<0:f+=x*k
else:g+=x*k
a=set(a)
with Pool(9)as p:
 for s in p.map(q,range(1,k+1)):a|=set(s)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-a]))

Submission status: Time Limit Exceeded

Solution code:
from multiprocessing import *
k=int(input().split()[1])-1
x=y=d=e=f=g=0
a=[(0,0)]
def q(i):return[(u+i*x,v+i*y)for u,v in a]
for s in input():
 if'E'==s:x+=1;g=[g,x][g<x]
 if'N'==s:y+=1;e=[e,y][e<y]
 if'W'==s:x-=1;f=[f,x][f>x]
 if'S'==s:y-=1;d=[d,y][d>y]
 a+=[(x,y)]
if y<0:d+=y*k
else:e+=y*k
if x<0:f+=x*k
else:g+=x*k
a=set(a)
with Pool(9)as p:
 for s in p.map(q,range(1,k+1)):a|=set(s)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-a]))

Submission status: Time Limit Exceeded

Solution code:
from multiprocessing import *
k=int(input().split()[1])-1
x=y=d=e=f=g=0
a=[(0,0)]
def q(i):return[(u+i*x,v+i*y)for u,v in a]
for s in input():
 if'S'==s:y-=1;d=[d,y][d>y]
 elif'N'==s:y+=1;e=[e,y][e<y]
 elif'W'==s:x-=1;f=[f,x][f>x]
 else:x+=1;g=[g,x][g<x]
 a+=[(x,y)]
if y<0:d+=y*k
else:e+=y*k
if x<0:f+=x*k
else:g+=x*k
a=set(a)
with Pool(9)as p:
 for s in p.map(q,range(1,k+1)):a|=set(s)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-a]))

Submission status: Time Limit Exceeded

Solution code:
from multiprocessing import *
k=int(input().split()[1])-1
x=y=d=e=f=g=0
a=[(0,0)]
def q(i):return[(u+i*x,v+i*y)for u,v in a]
for s in input():
 if'S'==s:y-=1;d=[d,y][d>y]
 elif'N'==s:y+=1;e=[e,y][e<y]
 elif'W'==s:x-=1;f=[f,x][f>x]
 else:x+=1;g=[g,x][g<x]
 a+=[(x,y)]
if y<0:d+=y*k
else:e+=y*k
if x<0:f+=x*k
else:g+=x*k
a=set(a)
if x==y==0:
 with Pool(9)as p:
  for s in p.map(q,range(1,k+1)):a|=set(s)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-a]))

Submission status: Time Limit Exceeded

Solution code:
from multiprocessing import *
k=int(input().split()[1])-1
x=y=d=e=f=g=0
a=[(0,0)]
def q(i):return[(u+i*x,v+i*y)for u,v in a]
for s in input():
 if'S'==s:y-=1;d=[d,y][d>y]
 elif'N'==s:y+=1;e=[e,y][e<y]
 elif'W'==s:x-=1;f=[f,x][f>x]
 else:x+=1;g=[g,x][g<x]
 a+=[(x,y)]
if y<0:d+=y*k
else:e+=y*k
if x<0:f+=x*k
else:g+=x*k
a=set(a)
for s in Pool(9).map(q,range(1,k+1)):a|=set(s)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-a]))

Submission status: Time Limit Exceeded

Solution code:
from multiprocessing import *
k=int(input().split()[1])-1
x=y=d=e=f=g=0
a=[(0,0)]
def q(i):return[(u+i*x,v+i*y)for u,v in a]
for s in input():
 if s in'SN':
  if'S'==s:y-=1;d=[d,y][d>y]
  else:y+=1;e=[e,y][e<y]
 else:
  if'W'==s:x-=1;f=[f,x][f>x]
  else:x+=1;g=[g,x][g<x]
 a+=[(x,y)]
if y<0:d+=y*k
else:e+=y*k
if x<0:f+=x*k
else:g+=x*k
a=set(a)
with Pool(9)as p:
 for s in p.map(q,range(1,k+1)):a|=set(s)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-a]))

Submission status: Time Limit Exceeded

Solution code:
k=int(input().split()[1])
p=input()
x=y=0
a=set([(0,0)])
for _ in[0]*k:
 for s in p:
  if'E'==s:x+=1
  if'N'==s:y+=1
  if'W'==s:x-=1
  if'S'==s:y-=1
  a|=set([(x,y)])
print(sum([1 for x,y in a if set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])<a]))

Submission status: Time Limit Exceeded

Solution code:
k=int(input().split()[1])
x=y=0
a=set([(0,0)])
for s in input():
 if'E'==s:x+=1
 if'N'==s:y+=1
 if'W'==s:x-=1
 if'S'==s:y-=1
 a|=set([(x,y)])
b=a.copy()
for u,v in a:b|=set([(u+x*i,v+y*i)for i in range(1,k)])
print(sum([1 for x,y in b if set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])<b]))

Submission status: Time Limit Exceeded

Solution code:
k=int(input().split()[1])
x=y=0
a=set([(0,0)])
for s in input():
 if'E'==s:x+=1
 if'N'==s:y+=1
 if'W'==s:x-=1
 if'S'==s:y-=1
 a|=set([(x,y)])
b=set(a)
for u,v in a:b|=set([(u+x*i,v+y*i)for i in range(1,k)])
print(sum([1 for x,y in b if set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])<b]))

Submission status: Time Limit Exceeded

Solution code:
k=int(input().split()[1])
x=y=0
a=set([(0,0)])
for s in input():
 if'E'==s:x+=1
 if'N'==s:y+=1
 if'W'==s:x-=1
 if'S'==s:y-=1
 a|=set([(x,y)])
b=set(a)
for i in range(1,k):b|=set([(u+x*i,v+y*i)for u,v in a])
print(sum([1 for x,y in b if set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])<b]))

Submission status: Time Limit Exceeded

Solution code:
k=int(input().split()[1])
x=y=0
a={(0,0)}
for s in input():
 if'E'==s:x+=1
 if'N'==s:y+=1
 if'W'==s:x-=1
 if'S'==s:y-=1
 a|={(x,y)}
b=set(a)
for i in range(1,k):b|={(u+x*i,v+y*i)for u,v in a}
print(sum([1 for x,y in b if{(x,y),(x+1,y),(x,y+1),(x+1,y+1)}<b]))

Submission status: Time Limit Exceeded

Solution code:
k=int(input().split()[1])
x=y=0
a=[(0,0)]
for s in input():
 if'E'==s:x+=1
 if'N'==s:y+=1
 if'W'==s:x-=1
 if'S'==s:y-=1
 a+=[(x,y)]
a={(u+x*i,v+y*i)for u,v in a for i in range(k)}
print(sum({(x,y),(x+1,y),(x,y+1),(x+1,y+1)}<a for x,y in a))

Submission status: Time Limit Exceeded

Solution code:
k=int(input().split()[1])
x,y=-1,0
a={}
for s in 'E'+input()*k:
 if s in'EW':x+=[-1,1]['E'==s]
 else:y+=[-1,1]['N'==s]
 for p in[(x,y),(x-1,y),(x-1,y-1),(x,y-1)]:a.setdefault(p,set()).add((x,y))
print(sum(len(c)>3 for c in a.values()))

Submission status: Time Limit Exceeded

Solution code:
k=int(input().split()[1])
x,y=-1,0
a={}
for s in'E'+input()*k:
 if s in'EW':x+=[-1,1]['E'==s]
 else:y+=[-1,1]['N'==s]
 [a.setdefault(p,set()).add((x,y))for p in[(x,y),(x-1,y),(x-1,y-1),(x,y-1)]]
print(sum(len(c)>3 for c in a.values()))

Submission status: Time Limit Exceeded

Solution code:
import sys
k=int(input().split()[1])
x,y=-1,0
a={}
for s in'E'+sys.stdin.readline().strip()*k:
 if s in'EW':x+=[-1,1]['E'==s]
 else:y+=[-1,1]['N'==s]
 [a.setdefault(p,set()).add((x,y))for p in[(x,y),(x-1,y),(x-1,y-1),(x,y-1)]]
print(sum(len(c)>3 for c in a.values()))

Submission status: Time Limit Exceeded

Solution code:
import sys
k=int(sys.stdin.readline().split()[1])
x,y=-1,0
a={}
for s in'E'+sys.stdin.readline().strip()*k:
 if s in'EW':x+=[-1,1]['E'==s]
 else:y+=[-1,1]['N'==s]
 [a.setdefault(p,set()).add((x,y))for p in[(x,y),(x-1,y),(x-1,y-1),(x,y-1)]]
print(sum(len(c)>3 for c in a.values()))

Submission status: Time Limit Exceeded

Solution code:
k=int(input().split()[1])
x,y=-1,0
a={}
for s in'E'+input()*k:
 if s in'EW':x+=[-1,1]['E'==s]
 else:y+=[-1,1]['N'==s]
 for p in[(x,y),(x-1,y),(x-1,y-1),(x,y-1)]:a.setdefault(p,set()).add((x,y))
print(sum([len(c)>3 for c in a.values()]))

Submission status: Memory Limit Exceeded

Solution code:
from multiprocessing import *
k=int(input().split()[1])-1
x=y=d=e=f=g=0
a=[(0,0)]
def q(i):return[(u+i*x,v+i*y)for u,v in a]
for s in input():
 if s in'SN':
  if'S'==s:y-=1
  else:y+=1
 else:
  if'W'==s:x-=1
  else:x+=1
 a+=[(x,y)]
a=set(a)
with Pool(9)as p:
 for s in p.map(q,range(1,k+1)):a|=set(s)
print(sum([1 for x,y in a if set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])<a]))

Submission status: Memory Limit Exceeded

Solution code:
k=int(input().split()[1])
p=input()
x=y=0
a=[(0,0)]
for _ in[0]*k:
 for s in p:
  if'E'==s:x+=1
  if'N'==s:y+=1
  if'W'==s:x-=1
  if'S'==s:y-=1
  a+=[(x,y)]
a=set(a)
print(sum([1 for x,y in a if set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])<a]))

Submission status: Memory Limit Exceeded

Solution code:
from multiprocessing import *
k=int(input().split()[1])
p=input()
x=y=0
a=[(0,0)]
def q(i):return[(u+i*x,v+i*y)for u,v in a]
for s in p:
 if'E'==s:x+=1
 if'N'==s:y+=1
 if'W'==s:x-=1
 if'S'==s:y-=1
 a+=[(x,y)]
a=set(a)
with Pool(9)as p:
 for s in p.map(q,range(1,k)):a|=set(s)
print(sum([1 for x,y in a if set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])<a]))

Submission status: Memory Limit Exceeded

Solution code:
from multiprocessing import *
k=int(input().split()[1])
p=input()
x=y=0
a=set([(0,0)])
def q(i):return[(u+i*x,v+i*y)for u,v in a]
for s in p:
 if'E'==s:x+=1
 if'N'==s:y+=1
 if'W'==s:x-=1
 if'S'==s:y-=1
 a|=set([(x,y)])
with Pool(9)as p:
 for s in p.map(q,range(1,k)):a|=set(s)
print(sum([1 for x,y in a if set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])<a]))

Submission status: Memory Limit Exceeded

Solution code:
from multiprocessing import *
k=int(input().split()[1])
p=input()
x=y=0
a=set([(0,0)])
def q(i):return[(u+i*x,v+i*y)for u,v in a]
for s in p:
 if'E'==s:x+=1
 if'N'==s:y+=1
 if'W'==s:x-=1
 if'S'==s:y-=1
 a|=set([(x,y)])
with Pool(4)as p:
 for s in p.map(q,range(1,k)):a|=set(s)
print(sum([1 for x,y in a if set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])<a]))

Submission status: Memory Limit Exceeded

Solution code:
k=int(input().split()[1])
p=input()
x=y=0
a=set([(0,0)])
for s in p:
 if'E'==s:x+=1
 if'N'==s:y+=1
 if'W'==s:x-=1
 if'S'==s:y-=1
 a|=set([(x,y)])
a|=set([(u+x*i,v+y*i)for i in range(1,k)for u,v in a])
print(sum([1 for x,y in a if set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])<a]))

Submission status: Memory Limit Exceeded

Solution code:
k=int(input().split()[1])
x=y=0
a={(0,0)}
for s in input():
 if'E'==s:x+=1
 if'N'==s:y+=1
 if'W'==s:x-=1
 if'S'==s:y-=1
 a|={(x,y)}
b=set(a)
for i in range(1,k):b|={(u+x*i,v+y*i)for u,v in a}
print(sum(1 for x,y in b if{(x,y),(x+1,y),(x,y+1),(x+1,y+1)}<b))

Submission status: Memory Limit Exceeded

Solution code:
k=int(input().split()[1])
x=y=0
a={(0,0)}
for s in input():
 if'E'==s:x+=1
 if'N'==s:y+=1
 if'W'==s:x-=1
 if'S'==s:y-=1
 a|={(x,y)}
b=set(a)
b|={(u+x*i,v+y*i)for u,v in a for i in range(1,k)}
print(sum(1 for x,y in b if{(x,y),(x+1,y),(x,y+1),(x+1,y+1)}<b))

Submission status: Memory Limit Exceeded

Solution code:
k=int(input().split()[1])
x=y=0
a={(0,0)}
for s in input():
 if'E'==s:x+=1
 if'N'==s:y+=1
 if'W'==s:x-=1
 if'S'==s:y-=1
 a|={(x,y)}
a={(u+x*i,v+y*i)for u,v in a for i in range(k)}
print(sum(1 for x,y in a if{(x,y),(x+1,y),(x,y+1),(x+1,y+1)}<a))

Submission status: Memory Limit Exceeded

Solution code:
k=int(input().split()[1])
x=y=0
a={(0,0)}
for s in input():
 if'E'==s:x+=1
 if'N'==s:y+=1
 if'W'==s:x-=1
 if'S'==s:y-=1
 a|={(x,y)}
a={(u+x*i,v+y*i)for u,v in a for i in range(k)}
print(sum(int({(x,y),(x+1,y),(x,y+1),(x+1,y+1)}<a)for x,y in a))

Submission status: Memory Limit Exceeded

Solution code:
k=int(input().split()[1])
x=y=0
a={(0,0)}
for s in input():
 if'E'==s:x+=1
 if'N'==s:y+=1
 if'W'==s:x-=1
 if'S'==s:y-=1
 a|={(x,y)}
a={(u+x*i,v+y*i)for u,v in a for i in range(k)}
print(sum({(x,y),(x+1,y),(x,y+1),(x+1,y+1)}<a for x,y in a))

Submission status: Memory Limit Exceeded

Solution code:
k=int(input().split()[1])
x=y=0
a={(0,0)}
for s in input():
 if'E'==s:x+=1
 elif'N'==s:y+=1
 elif'W'==s:x-=1
 else:y-=1
 a|={(x,y)}
a={(u+x*i,v+y*i)for u,v in a for i in range(k)}
print(sum({(x,y),(x+1,y),(x,y+1),(x+1,y+1)}<a for x,y in a))

Submission status: Memory Limit Exceeded

Solution code:
k=int(input().split()[1])
x=y=0
a={(0,0)}
for s in input():
 if s in 'EW':x+=[-1,1]['E'==s]
 if s in 'NS':y+=[-1,1]['N'==s]
 a|={(x,y)}
a={(u+x*i,v+y*i)for u,v in a for i in range(k)}
print(sum({(x,y),(x+1,y),(x,y+1),(x+1,y+1)}<a for x,y in a))

Submission status: Memory Limit Exceeded

Solution code:
k=int(input().split()[1])
x=y=0
a={(0,0)}
for s in input():
 if s in'EW':x+=[-1,1]['E'==s]
 if s in'NS':y+=[-1,1]['N'==s]
 a|={(x,y)}
a={(u+x*i,v+y*i)for u,v in a for i in range(k)}
print(sum({(x,y),(x+1,y),(x,y+1),(x+1,y+1)}<a for x,y in a))

Submission status: Memory Limit Exceeded

Solution code:
k=int(input().split()[1])
x=y=0
a={(0,0)}
for s in input():
 if s in'EW':x+=[-1,1]['E'==s]
 else:y+=[-1,1]['N'==s]
 a|={(x,y)}
a={(u+x*i,v+y*i)for u,v in a for i in range(k)}
print(sum({(x,y),(x+1,y),(x,y+1),(x+1,y+1)}<a for x,y in a))

Submission status: Memory Limit Exceeded

Solution code:
def f(s):
 global x,y
 if s in'EW':x+=[-1,1]['E'==s]
 else:y+=[-1,1]['N'==s]
 return(x,y)
k=int(input().split()[1])
x=y=0
a={(u+x*i,v+y*i)for u,v in{f(s)for s in input()}|{(0,0)}for i in range(k)}
print(sum({(x,y),(x+1,y),(x,y+1),(x+1,y+1)}<a for x,y in a))

Submission status: Memory Limit Exceeded

Solution code:
k=int(input().split()[1])
x=y=0
def f(s):
 global x,y
 if s in'EW':x+=[-1,1]['E'==s]
 else:y+=[-1,1]['N'==s]
 return(x,y)
a={(u+x*i,v+y*i)for u,v in{f(s)for s in input()}|{(0,0)}for i in range(k)}
print(sum({(x,y),(x+1,y),(x,y+1),(x+1,y+1)}<a for x,y in a))

Submission status: Memory Limit Exceeded

Solution code:
k=int(input().split()[1])
x=y=0
def f(s):
 global x,y
 if s in'EW':x+=[-1,1]['E'==s]
 else:y+=[-1,1]['N'==s]
 return(x,y)
a={f(s)for s in input()}|{(0,0)}
a={(u+x*i,v+y*i)for u,v in a for i in range(k)}
print(sum({(x,y),(x+1,y),(x,y+1),(x+1,y+1)}<a for x,y in a))

Submission status: Memory Limit Exceeded

Solution code:
x=y=0
def f(s):
 global x,y
 if s in'EW':x+=[-1,1]['E'==s]
 else:y+=[-1,1]['N'==s]
 return(x,y)
k=int(input().split()[1])
a={(u+x*i,v+y*i)for u,v in{f(s)for s in input()}|{(0,0)}for i in range(k)}
print(sum([{(x,y),(x+1,y),(x,y+1),(x+1,y+1)}<a for x,y in a]))

Submission status: Runtime Error

Solution code:
k=int(input().split()[1])
p=input()
x=y=d=e=f=g=0
a=[(0,0)]
for _ in[0]*k:
 for s in p:
  if'E'==s:x+=1;g=[g,x][g<x]
  if'N'==s:y+=1;e=[e,y][e<y]
  if'W'==s:x-=1;f=[f,x][f>x]
  if'S'==s:y-=1;d=[d,y][d>y]
  a+=[(x,y)]
print(sum([1 for y in range(d,e)for x in range(f,g)if all((x,y)in a,(x+1,y)in a,(x,y+1)in a,(x+1,y+1)in a)]))

Submission status: Runtime Error

Solution code:
k=int(input().split()[1])
p=input()
x=y=d=e=f=g=0
a=[(0,0)]
for _ in[0]*k:
 for s in p:
  if'E'==s:x+=1;g=[g,x][g<x]
  if'N'==s:y+=1;e=[e,y][e<y]
  if'W'==s:x-=1;f=[f,x][f>x]
  if'S'==s:y-=1;d=[d,y][d>y]
  a+=[(x,y)]
s=set(a)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-s)]))

Submission status: Runtime Error

Solution code:
k=int(input().split()[1])
p=input()
x=y=d=e=f=g=0
a=[(0,0)]
for _ in[0]*k:
 for s in p:
  if'E'==s:x+=1;g=[g,x][g<x]
  if'N'==s:y+=1;e=[e,y][e<y]
  if'W'==s:x-=1;f=[f,x][f>x]
  if'S'==s:y-=1;d=[d,y][d>y]
  a+=[(x,y)]
s=set(a)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-s)])

Submission status: Runtime Error

Solution code:
import collections
k=int(input().split()[1])-1
p=input()
x=y=d=e=f=g=0
a=collections.deque([(0,0)])
for s in p:
 if'E'==s:x+=1;g=[g,x][g<x]
 if'N'==s:y+=1;e=[e,y][e<y]
 if'W'==s:x-=1;f=[f,x][f>x]
 if'S'==s:y-=1;d=[d,y][d>y]
 a.append((x,y))
g+=x*k if x>0 else f+=x*k
if y>0:e+=y*k
else:d+=y*k
for t in set(a):
 for i in range(1,k+1):
   a.append((t[0]+i*x,t[1]+i*y))
s=set(a)
print(sum([1 for y in range(d,e)for x in range(f,g)if not set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])-s]))

Submission status: Runtime Error

Solution code:
k=int(input().split()[1])
p=input()
x=y=0
a=[(0,0)]
for _ in[0]*k:
 for s in p:
  if'E'==s:x+=1
  if'N'==s:y+=1
  if'W'==s:x-=1
  if'S'==s:y-=1
  a+=[(x,y)]
s=set(a)
print(sum([1 for x,y in a if set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])<a]))

Submission status: Runtime Error

Solution code:
k=int(input().split()[1])
x=y=0
a=set([(0,0)])
for _ in[0]*k:
 for s in input():
  if'E'==s:x+=1
  if'N'==s:y+=1
  if'W'==s:x-=1
  if'S'==s:y-=1
  a|=set([(x,y)])
print(sum([1 for x,y in a if set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])<a]))

Submission status: Runtime Error

Solution code:
from multiprocessing import *
k=int(input().split()[1])
p=input()
x=y=0
a=[(0,0)]
for _ in[0]*k:
 for s in p:
  if'E'==s:x+=1
  if'N'==s:y+=1
  if'W'==s:x-=1
  if'S'==s:y-=1
  a+=[(x,y)]
a=set(a)
with Pool(9)as p:
 for s in p.map(q,range(1,k+1)):a|=set(s)
print(sum([1 for x,y in a if set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])<a]))

Submission status: Runtime Error

Solution code:
k=int(input().split()[1])
p=input()
x=y=0
a=set([(0,0)])
for s in p:
 if'E'==s:x+=1
 if'N'==s:y+=1
 if'W'==s:x-=1
 if'S'==s:y-=1
 a|=set([(x,y)])
for u,v in a:a|=set([(u+x*i,v+y*i)for i in range(1,k)])
print(sum([1 for x,y in a if set([(x,y),(x+1,y),(x,y+1),(x+1,y+1)])<a]))

Submission status: Runtime Error

Solution code:
k=int(input().split()[1])
x=y=0
a={(0,0)}
for s in input():
 if'E'==s:x+=1
 if'N'==s:y+=1
 if'W'==s:x-=1
 if'S'==s:y-=1
 a|=[(x,y)]
a={(u+x*i,v+y*i)for u,v in a for i in range(k)}
print(sum({(x,y),(x+1,y),(x,y+1),(x+1,y+1)}<a for x,y in a))

Submission status: Runtime Error

Solution code:
k=int(input().split()[1])
x=y=0
a={(0,0)}
for s in input():
 if'E'==s:x+=1
 elif'N'==s:y+=1
 elif'W'==s:x-=1
 elses:y-=1
 a|={(x,y)}
a={(u+x*i,v+y*i)for u,v in a for i in range(k)}
print(sum({(x,y),(x+1,y),(x,y+1),(x+1,y+1)}<a for x,y in a))