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
s907113196
p03920
u879870653
1547912494
Python
Python (3.4.3)
py
Runtime Error
17
3060
296
N = int(input()) L = [0] l = 0 for i in range(1,100) : l += i L.append(l) ans = [] while N > 0 : for i in range(len(L)) : #print(L[i],N,L[i+1]) if (L[i]+1 <= N <= L[i+1]) : ans.append(i+1) N -= i+1 break print(*ans,sep="\n")
s354897752
p03920
u631277801
1535731141
Python
Python (3.4.3)
py
Runtime Error
22
3828
303
from bisect import bisect_right sum_list = [] nm = 1 sm = 1 while sm <= 10**7: sum_list.append(sm) nm += 1 sm += nm n = int(input()) k = bisect_right(sum_list, n) ans_set = set([i for i in range(1,k+2)]) ans_set.remove(sum_list[k] - n) ans = list(ans_set) for a in ans: print(a)
s645163109
p03920
u856232850
1524723379
Python
Python (3.4.3)
py
Runtime Error
21
3572
128
n = int(input()) a = int((2*n)**0.5)+1 b = int((a*(a+1))/2)-n c = [i for i in range(1,a+1)] c.remove(b) for i in c: print(i)
s895939663
p03920
u986399983
1511481446
Python
Python (3.4.3)
py
Runtime Error
17
2940
862
#include<cstdio> #include<cstdlib> #include<cmath> #include<iostream> #include<string> #include<stack> #include<queue> #include<vector> #include<map> #include<set> #include<algorithm> #include<numeric> #define rep(n) for(int i=0;i<n;i++) #define repp(j, n) for(int j=0;j<n;j++) #define reppp(i, m, n) for(int i=m;i<=n;i++) #define all(c) c.begin(), c.end() #define rall(c) c.rbegin(), c.rend() #define MOD 1000000007 #define MAX 100000 #define INF 1410065408 #define EPS 1e-9 #define DEBUG 0 #define ll long long #define Pll pair<ll, ll> #define Pii pair<int, int> using namespace std; struct edge{int from, to; ll cost;}; //int G[MAX][MAX]; signed main(){ ios::sync_with_stdio(0); cin.tie(0); int n, a; cin >> n; if(n == 1){ cout << 1; return 0; } a = (n+2)/2; cout << a << endl << n-a << endl; return 0; }
s890326082
p03920
u840684628
1507948909
Python
Python (3.4.3)
py
Runtime Error
75
4404
257
def calc(n): i=1 sm = 0 st = set() if n<=2: st.add(n) return st while sm<=n: st.add(i) sm += i i+=1 st = st - calc(sm-n) return st n = int(input()) c = calc(n) for cc in c: print(cc)
s920628806
p03920
u840684628
1507948795
Python
Python (3.4.3)
py
Runtime Error
79
4408
257
def calc(n): i=1 sm = 0 st = set() if n<=2: st.add(n) return st while sm<=n: st.add(i) sm += i i+=1 st = st - calc(sm-n) return st n = int(input()) c = calc(n) for cc in c: print(cc)
s432073785
p03920
u194412908
1501162453
Python
PyPy3 (2.4.0)
py
Runtime Error
225
43376
176
import math N = int(input()) sum =0 for i in range(1,N): sum += i if sum>=N: break for j in range(1,i+1): if j == sum-N: continue print(j)
s019104794
p03920
u237168895
1480186280
Python
Python (3.4.3)
py
Runtime Error
108
4236
532
a = int(input().strip()) tmp = [] res = [] ind = 1 def bar(foo,hoge): if(foo == 0): return if foo == 1: res.append(1) return elif foo == 2: res.append(2) return for i in reversed(range(hoge)): if (tmp[i] <= foo): res.append(i + 1) bar(foo - (i + 1) , i) return for i in range(10000000): ind = ind + i tmp.append(ind) if ind >= a : bar(a, i + 1 ) break for i in res: print(i)
s088364943
p03920
u174620969
1480185748
Python
Python (3.4.3)
py
Runtime Error
22
3064
302
import sys f = open('input.txt') # f = input() N = int(f.readline()) out = [] sum = 0 for i in range(0, N+1): sum = sum + i out.append(i) if sum > N: r = sum - N out.remove(r) break out.remove(0) for n in out: print(n) # print(' '.join(map(str, out)))
s213829690
p03921
u893063840
1585338914
Python
PyPy3 (2.4.0)
py
Runtime Error
836
87896
1283
class UnionFind: def __init__(self, n): self.n = n self.p = [e for e in range(n)] self.rank = [0] * n self.size = [1] * n def same(self, u, v): return self.find_set(u) == self.find_set(v) def unite(self, u, v): u = self.find_set(u) v = self.find_set(v) if u == v: return if self.rank[u] > self.rank[v]: self.p[v] = u self.size[u] += self.size[v] else: self.p[u] = v self.size[v] += self.size[u] if self.rank[u] == self.rank[v]: self.rank[v] += 1 def find_set(self, u): if u != self.p[u]: self.p[u] = self.find_set(self.p[u]) return self.p[u] def update_p(self): for u in range(self.n): self.find_set(u) def get_size(self, u): return self.size[self.find_set(u)] n, m = map(int, input().split()) l = [] for _ in range(n): k, *ls = map(int, input().split()) l.append(ls) uf = UnionFind(m) for li in l: for e1, e2 in zip(li, li[1:]): e1 -= 1 e2 -= 1 uf.unite(e1, e2) p = uf.find_set(l[0][0]) ans = "YES" for e, *_ in l: e -= 1 if uf.find_set(e) != p: ans = "NO" print(ans)
s418891386
p03921
u171366497
1561437400
Python
Python (3.4.3)
py
Runtime Error
20
3444
540
N,M=map(int,input().split()) from collections import defaultdict dist=[d]*N branch=defaultdict(set) lang=defaultdict(set) inp=[] for i in range(N): X=list(map(int,input().split())) for k in range(X[0]): lang[X[k+1]]|={i} inp.append(X[1:]) for i in range(N): for l in inp[i]: branch[i]|=lang[l] checked={0} check={0} while len(check)>0: now=check.pop() check|=branch[now]-checked checked|=branch[now] if len(checked)==N: break if len(checked)==N: print('YES') else: print('NO')
s162966022
p03921
u620084012
1560331182
Python
PyPy3 (2.4.0)
py
Runtime Error
627
74528
591
N, M = map(int,input().split()) H = [] L = [[] for k in range(M+1)] for k in range(N): P = list(map(int,input().split()))[1:] H.append(P) for e in P: L[e].append(k+1) G = [0 for k in range(N+1)] G[1] = 1 Q = [H[0]] while len(Q) > 0: ima = Q.pop() if len(ima) == 1 and G[ima[0]] == 1: pass for tsugi in ima: for e in L[tsugi]: if G[e] == 0: G[e] = 1 if len(H[e-1]) > 1: Q.append(H[e-1]) for k in range(1,N+1): if G[k] == 0: print("NO") exit(0) print("YES")
s101427573
p03921
u214617707
1559303572
Python
Python (3.4.3)
py
Runtime Error
503
13460
719
N, M = map(int, input().split()) parent = [i for i in range(N + M)] rank = [0] * (N + M) def find(i): if parent[i] == i: return i else: parent[i] = find(parent[i]) return parent[i] def same(x, y): return find(x) == find(y) def unite(x, y): x = find(x) y = find(y) if x == y: return if rank[x] > rank[y]: parent[y] = x else: parent[x] = y if rank[x] == rank[y]: rank[y] += 1 for i in range(N): P = list(map(int, input().split())) n = P[0] for j in range(1, n + 1): unite(N + i, P[j] - 1) k = find(0) for i in range(N): if k != find(i): print('NO') exit() print('YES')
s069437189
p03921
u099643902
1557691527
Python
Python (3.4.3)
py
Runtime Error
597
18180
748
N, M = map(int, input().split()) graph = [[] for i in range(M)] for i in range(N): L = list(map(int, input().split())) for j in range(1,L[0]+1): graph[L[j]-1].append(i) def root(x): if par[x] == x: return(x) else: y = root(par[x]) par[x] = y return y def unite(x,y): x = root(x) y = root(y) if x==y: return par[x] = y def same(x,y): return root(x) == root(y) par = [i for i in range(N)] for i in range(M): lang = graph[i] if len(lang) > 1: for j in range(1,len(lang)): unite(lang[0], lang[j]) flag = True for i in range(1, N): if not same(0, i): flag = False break if flag: print('YES') else: print('NO')
s082505597
p03921
u099643902
1557691302
Python
Python (3.4.3)
py
Runtime Error
612
18208
740
N, M = map(int, input().split()) graph = [[] for i in range(M)] for i in range(N): L = list(map(int, input().split())) for j in range(1,L[0]+1): graph[L[j]-1].append(i) def root(x): if par[x] == x: return(x) else: par[x] = root(par[x]) return(par[x]) def unite(x,y): x = root(x) y = root(y) if x==y: return par[x] = y def same(x,y): return root(x) == root(y) par = [i for i in range(N)] for i in range(M): lang = graph[i] if len(lang) > 1: for j in range(1,len(lang)): unite(lang[0], lang[j]) flag = True for i in range(1, N): if not same(0, i): flag = False break if flag: print('YES') else: print('NO')
s760221806
p03921
u099643902
1557690025
Python
Python (3.4.3)
py
Runtime Error
616
18180
765
N, M = map(int, input().split()) graph = [[] for i in range(M)] for i in range(N): L = list(map(int, input().split())) if L[0] >= 1: for j in range(1,L[0]+1): graph[L[j]-1].append(i) def root(x): if par[x] == x: return(x) else: par[x] = root(par[x]) return(par[x]) def unite(x,y): x = root(x) y = root(y) if x==y: return par[x] = y def same(x,y): return root(x) == root(y) par = [i for i in range(N)] for i in range(M): lang = graph[i] if len(lang) > 1: for j in range(1,len(lang)): unite(lang[0], lang[j]) flag = True for i in range(N-1): if not same(i, i+1): flag = False break if flag: print('YES') else: print('NO')
s226071137
p03921
u099643902
1557689747
Python
Python (3.4.3)
py
Runtime Error
643
18204
739
N, M = map(int, input().split()) graph = [[] for i in range(M)] for i in range(N): L = list(map(int, input().split())) for j in range(1,L[0]+1): graph[L[j]-1].append(i) def root(x): if par[x] == x: return(x) else: par[x] = root(par[x]) return(par[x]) def unite(x,y): x = root(x) y = root(y) if x==y: return par[x] = y def same(x,y): return root(x) == root(y) par = [i for i in range(N)] for i in range(M): lang = graph[i] if len(lang) > 1: for j in range(1,len(lang)): unite(lang[0], lang[j]) flag = True for i in range(N-1): if not same(i, i+1): flag = False break if flag: print('YES') else: print('NO')
s913875517
p03921
u619819312
1556023999
Python
Python (3.4.3)
py
Runtime Error
485
37552
388
import sys sys.setrecursionlimit(10**9) n,m=map(int,input().split()) a=[[]for i in range(n+m)] for i in range(n): s=list(map(int,input().split())) for j in s[1:]: a[i].append(j+n-i) a[n+j-1].append(i) t=[False]*(n+m) def g(x): t[x]=True for i in a[x]: if not t[i]: g(i) g(0) if all(t[:n]): print("YES") else: print("NO")
s746102025
p03921
u619819312
1556023594
Python
Python (3.4.3)
py
Runtime Error
18
2940
417
import sys sys.setrecursionlimit(10**6) n,m=map(int,input().split()) a=[[]for i in range(n+m)] for i in range(n): s=list(map(int,input().split())) for j in s[1:]: a[i].append(j) a[n+j].append(i) t=[False]*n def g(x): if not t[x]: t[x]=False: for i in a[x]: for j in a[i+n]: g(j) g(0) if all(t): print("YES") else: print("NO")
s852841492
p03921
u077337864
1555106512
Python
Python (3.4.3)
py
Runtime Error
581
29824
454
n, m = map(int, input().split()) people = [] lang = [[] for _ in range(m)] for i in range(n): kl = list(map(int, input().split())) k = kl[0] people.append(kl[1:]) for l in kl[1:]: lang[l-1].append(i) visited = [False for _ in range(n)] def dfs(i): if visited[i]: return else: visited[i] = True for l in people[i]: for nexp in lang[l-1]: dfs(nexp) dfs(0) if all(visited): print('YES') else: print('NO')
s807724782
p03921
u177398299
1536706698
Python
Python (3.4.3)
py
Runtime Error
636
12692
484
N, M = map(int, input().split()) parent = [i for i in range(N + M)] def find(x): if x == parent[x]: return x parent[x] = find(parent[x]) return parent[x] def unite(x, y): x, y = find(x), find(y) if x == y: return parent[y] = x for i in range(N): for l in list(map(int, input().split()))[1:]: # 言語はparentの後半 unite(i, N + l - 1) if all(find(0) == find(i) for i in range(N)): print('YES') else: print('NO')
s661218512
p03921
u075012704
1533752361
Python
Python (3.4.3)
py
Runtime Error
499
36812
634
N, M = map(int, input().split()) P = [[] for i in range(N)] L = [[] for i in range(M)] for i in range(N): I = list(map(int, input().split())) for l in I[1:]: P[i].append(l-1) L[l-1].append(i) P_visited = [0] * N L_visited = [0] * M # flgが立っていれば、人を見ているとする def dfs(n, flg): if flg: P_visited[n] = 1 for l in P[n]: if not L_visited[l]: dfs(l, flg ^ 1) else: L_visited[n] = 1 for p in L[n]: if not P_visited[p]: dfs(p, flg ^ 1) dfs(0, 1) print("YES" if all(P_visited) else "NO")
s356510808
p03921
u761320129
1516049327
Python
Python (3.4.3)
py
Runtime Error
583
12664
518
N,M = map(int,input().split()) par = [i for i in range(N+M)] def root(a): if par[a] == a: return a par[a] = root(par[a]) return par[a] def same(a,b): return root(a) == root(b) def unite(a,b): ra,rb = root(a),root(b) if ra == rb: return par[ra] = rb for i in range(N): src = list(map(lambda x:int(x)-1,input().split())) if len(src) == 1: continue for j in src[1:]: unite(i,N+j) for i in range(1,N): if not same(0,i): print('NO') exit() print('YES')
s908140553
p03921
u761320129
1516048665
Python
Python (3.4.3)
py
Runtime Error
2104
12664
466
N,M = map(int,input().split()) par = [i for i in range(N+M)] def root(a): if par[a] == a: return a return root(par[a]) def same(a,b): return root(a) == root(b) def unite(a,b): ra,rb = root(a),root(b) if ra == rb: return par[ra] = rb for i in range(N): src = list(map(lambda x:int(x)-1,input().split())) for j in src[1:]: unite(i,N+j) for i in range(1,N): if not same(0,i): print('NO') exit() print('YES')
s593638498
p03921
u858748695
1515792033
Python
Python (3.4.3)
py
Runtime Error
18
3064
355
#!/usr/bin/env python3 from unionfind import unionfind N, M = map(int, input().split()) u = unionfind(N + M) for i in range(N): L = [int(x) - 1 for x in input().split()] L[0] += 1 for j in range(L[0]): u.unite(L[j + 1], M + i) ans = True for i in range(N): if not u.issame(M, M + i): ans = False print(('NO', 'YES')[ans])
s228366956
p03921
u858748695
1515104294
Python
Python (3.4.3)
py
Runtime Error
17
3060
239
#!/usr/bin/env python3 N = int(input()) sum = 0 m = 0 for i in range(1, 10**3 + 1): sum += i if sum >= N: m = i break sum = N for i in range(1, m + 1)[::-1]: if sum - i >= 0: sum -= i print(i)
s910778332
p03921
u123756661
1480192205
Python
Python (2.7.6)
py
Runtime Error
15
2580
25
4 4 2 1 2 2 1 2 1 3 2 4 3
s493059027
p03921
u509661905
1480183190
Python
PyPy3 (2.4.0)
py
Runtime Error
242
40048
1418
#!/usr/bin/env pypy3 class UnionFind(object): def __init__(self, number_of_nodes): self.par = list(range(number_of_nodes)) self.rank = [0] * number_of_nodes def root(self, node): if self.par[node] == node: return node else: r = self.root(self.par[node]) self.par[node] = r return r def in_the_same_set(self, node1, node2): return self.root(node1) == self.root(node2) def unite(self, node1, node2): x = self.root(node1) y = self.root(node2) if x != y: if self.rank[x] < self.rank[y]: x, y = y, x self.par[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 def main(): n, m = (int(x) for x in input().split()) assert n <= 1000 and m <= 1000 speakers = [[] for _ in range(m)] for contestant in range(n): languages = [int(x) - 1 for x in input().split()][1:] for language in languages: speakers[language].append(contestant) uf = UnionFind(n) for lang_speakers in speakers: for i in range(len(lang_speakers) - 1): uf.unite(lang_speakers[i], lang_speakers[i + 1]) for i in range(n): if not uf.in_the_same_set(0, i): print("NO") break else: print("YES") if __name__ == '__main__': main()
s821248974
p03922
u471797506
1480187252
Python
Python (2.7.6)
py
Runtime Error
246
12640
535
# -*- coding: utf-8 -*- import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll N, M = map(int, raw_input().split()) X = map(int, raw_input().split()) cnt = [0]*100005 for x in X: cnt[x%M] += 1 ans = 0 for i in xrange(M): if i == M - i: ans += cnt[i]/2 print "=", cnt[i] cnt[i] %= 2 else: m = min(cnt[i], cnt[M - i]) print min(cnt[i], cnt[M - i]) ans += m cnt[i] -= m cnt[M - i] -= m for i in xrange(M): ans += cnt print ans
s978216334
p03923
u163320134
1587624237
Python
PyPy3 (2.4.0)
py
Runtime Error
2111
1963416
224
n,a=map(int,input().split()) costs=[10**18]*(n+1) costs[1]=0 times=[0]*(n+1) for i in range(1,n+1): times[i]=costs[i]+(n+i-1)//i for j in range(2,n//i+1): costs[i*j]=min(costs[i*j],costs[i]+j+a) print(min(times[1:]))
s557529914
p03923
u929150664
1480800774
Python
Python (3.4.3)
py
Runtime Error
23
3192
828
#!/usr/bin/env python # -*- coding: utf-8 -*- def pow(a, b): if b == 1:return a if b%2 == 0: return pow(a*a, int(b/2)) return a*pow(a*a, int(b/2)) def binaryOne(n, multi): l, r = 0, n mid = (l + r)/2 while r - l > 1: if pow(mid, multi) >= n: r = mid else: l = mid mid = (r + l)/2 return r; def binaryTwo(n, maxi, multi): l, r = 0, multi mid = (l + r)/2 while r - l > 1: if pow(maxi, (multi - mid))*pow(maxi - 1, mid) >= n: l = mid else: r = mid mid = (r + l)/2; return l n, a = map(int,raw_input().split(" ")) ans = 1e18 for i in xrange(0, 40): maxi = binaryOne(n, i + 1); subt = binaryTwo(n, maxi, i + 1) ans = min(ans, a*i + maxi*(i + 1) - subt) print ans
s227548856
p03924
u104282757
1480193752
Python
PyPy2 (5.6.0)
py
Runtime Error
53
9840
639
import numpy as np N, M = map(int, raw_input().split()) # one way path from 1, no path from 1 status_mat = np.zeros((N, N), dtype='int') status_mat[0, N-1] = 1 bothM = np.zeros((N, N), dtype='int') for i in range(N): for j in range(N): bothM[i, j] = N-i-j diagM = np.diag(range(N)) def update_status_mat(status_mat): new_status_mat = diagM.dot(status_mat) new_status_mat[0, :] += (bothM*status_mat).sum(axis=0) new_status_mat[1:, :(N-1)] += status_mat.dot(diagM)[:(N-1), 1:] return new_status_mat % 1000000007 for m in range(M): status_mat = update_status_mat(status_mat) print status_mat[0,0]
s079240305
p03929
u802963389
1600659873
Python
Python (3.8.2)
py
Runtime Error
24
8916
334
n, k = map(int,input().split()) if n < 3: print(0) exit() table = [[0] * 5 for i in range(11)] for i in range(11): for j in range(5): t = 9 * (j + 2 + 7 * (i + 1)) table[i][j] = t % 11 c = [0] for row in table: c.append(c[-1] + row.count(K)) d,m = divmod(n - 2, 11) ans = c[m] + c[-1] * d print(ans)
s880738170
p03929
u785578220
1565927888
Python
PyPy3 (2.4.0)
py
Runtime Error
175
38384
34
a = input() b = input() print(a+b)
s562835889
p03929
u673338219
1540049925
Python
Python (3.4.3)
py
Runtime Error
17
3060
180
n,k = int(input()) a = [0,5,10,4,9,3,8,2,7,1,6] r = a[k] s = 0 for i in range(2,n): for j in [2,3,4,5,6]: if (7*i + j - 7 - r)%11 == 0: s += 1 print(s)
s803514093
p03929
u856232850
1525916158
Python
Python (3.4.3)
py
Runtime Error
17
3064
208
a = 4;b = 2;c = 0;d = 9;e = 7 f = [a,b,c,d,e] ans = 0 for i in range((n-2)%11): if k in (a,b,c,d,e): ans += 1 a = (a+8)%11 b = (b+8)%11 c = (c+8)%11 d = (d+8)%11 e = (e+8)%11 print(ans+((n-2)//11)*5)
s069908159
p03929
u272028993
1479785049
Python
PyPy2 (5.6.0)
py
Runtime Error
41
8944
423
mod=10**9+7 n,k=map(int,raw_input().split()) a=map(int,raw_input().split()) dp=[[[0]*(1<<8) for _ in xrange(n+1)] for _ in xrange(n+1)] for i in xrange(n): dp[i+1][1][a[i]]=1 for i in xrange(n): for j in xrange(n): for l in xrange(1<<8): dp[i+1][j+1][a[i]^l]+=(j+1)*dp[i][j][l]%mod dp[i+1][j][l]+=dp[i][j][l]%mod ans=0 for j in xrange(1,n+1): ans=(ans+dp[n][j][k])%mod print(ans)
s732919512
p03929
u247140408
1479699722
Python
Python (3.4.3)
py
Runtime Error
22
3064
490
n = int(input()) k = int(input()) vl = [] rl = [] for v in range(n): kari_value = [] for v2 in range(v*7+1, v*7+1+7): kari_value.append(v2) vl.append(kari_value) for v in range(len(vl)-2): # 縦の繰り返し for v2 in range(len(vl[0])-2): # 横の繰り返し s = vl[v][v2] + vl[v][v2+1] + vl[v][v2+2] + vl[v+1][v2] + vl[v+1][v2+1] + vl[v+1][v2+2] + vl[v+2][v2] + vl[v+2][v2+1] + vl[v+2][v2+2] if (s % 11 == k) : rl.append(1) print(sum(rl))
s225864024
p03929
u247140408
1479699482
Python
Python (3.4.3)
py
Runtime Error
24
3064
577
n = int(input()) k = int(input()) vl = [] rl = [] for v in range(n): kari_value = [] for v2 in range(v*7+1, v*7+1+7): kari_value.append(v2) vl.append(kari_value) # print(value_list) # print(len(value_list), len(value_list[0])) for v in range(len(vl)-2): # 縦の繰り返し for v2 in range(len(vl[0])-2): # 横の繰り返し s = vl[v][v2] + vl[v][v2+1] + vl[v][v2+2] + vl[v+1][v2] + vl[v+1][v2+1] + vl[v+1][v2+2] + vl[v+2][v2] + vl[v+2][v2+1] + vl[v+2][v2+2] # print(s % 11) if (s % 11 == k) : rl.append(1) print(sum(rl))
s517698760
p03930
u899782392
1598400551
Python
Python (3.8.2)
py
Runtime Error
25
9312
1331
H, W, K = map(int, input().split()) def clear(row, start, end, mult): if end - start + 1 < K: return 0 gain = 0 for i in range(start, end + 1): gain += mult * row[i] row[i] = 0 return gain def drop(board): for x in range(W): wp = 0 for y in range(H): if board[y][x] > 0: board[wp][x] = board[y][x] if wp != y: board[y][x] = 0 wp += 1 def proceed(board, mult): gain = 0 for row in board: start = -1 num = -1 for i in range(W): if row[i] == num: continue else: gain += clear(row, start, i-1, mult) num = row[i] start = i if num > 0: gain += clear(row, start, W-1, mult) drop(board) return gain board_ = [] for _ in range(H): board_.append(list(map(int, input()))) board_.reverse() ans = 0 for y in range(H): for x in range(W): board = deepcopy(board_) board[y][x] = 0 drop(board) mult = 1 cand = 0 while True: gain = proceed(board, mult) if gain == 0: break cand += gain mult *= 2 ans = max(ans, cand) print(ans)
s756573813
p03930
u899782392
1598400495
Python
Python (3.8.2)
py
Runtime Error
30
9340
1331
H, W, K = map(int, input().split()) def clear(row, start, end, mult): if end - start + 1 < K: return 0 gain = 0 for i in range(start, end + 1): gain += mult * row[i] row[i] = 0 return gain def drop(board): for x in range(W): wp = 0 for y in range(H): if board[y][x] > 0: board[wp][x] = board[y][x] if wp != y: board[y][x] = 0 wp += 1 def proceed(board, mult): gain = 0 for row in board: start = -1 num = -1 for i in range(W): if row[i] == num: continue else: gain += clear(row, start, i-1, mult) num = row[i] start = i if num > 0: gain += clear(row, start, W-1, mult) drop(board) return gain board_ = [] for _ in range(H): board_.append(list(map(int, input()))) board_.reverse() ans = 0 for y in range(H): for x in range(W): board = deepcopy(board_) board[y][x] = 0 drop(board) mult = 1 cand = 0 while True: gain = proceed(board, mult) if gain == 0: break cand += gain mult *= 2 ans = max(ans, cand) print(ans)
s188097877
p03930
u576432509
1597364192
Python
Python (3.8.2)
py
Runtime Error
143
9512
3221
from collections import deque icase=0 if icase==0: h,w,k=map(int,input().split()) aa=[[0]*w for i in range(h)] for i in range(h): ll=input() for j in range(w): aa[h-1-i][j]=int(ll[j]) elif icase==1: h,w,k=4,4,2 aa=[[2, 3, 1, 2], [1, 4, 2, 4], [4, 1, 2, 1], [3, 4, 1, 3]] elif icase==2: h,w,k=4,4,2 aa=[[2, 1, 2, 1], [1, 2, 1, 2], [2, 1, 2, 1], [1, 2, 1, 2]] elif icase==3: h,w,k=7,7,2 aa=[[8, 9, 8, 9, 8, 9, 8], [9, 8, 9, 8, 9, 8, 9], [8, 9, 8, 9, 8, 9, 8], [9, 8, 9, 8, 9, 8, 9], [8, 9, 8, 9, 8, 9, 8], [9, 8, 9, 8, 9, 8, 9], [8, 9, 8, 9, 8, 9, 8]] elif icase==4: h,w,k=17,17,2 aa=[[8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6], [7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5], [6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4], [5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3], [4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2], [3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1], [2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8], [9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7], [8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6], [7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5], [6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4], [5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3], [4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2], [3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1], [2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8]] # print(a) pmax=0 for j in range(h): a=[[0]*w for i in range(h)] for i in range(h): for j2 in range(w): a[i][j2]=aa[i][j2] # print("j:",j,a) for ii in range(h-1): a[ii][j]=a[ii+1][j] a[h-1][j]=0 # print("1:",a) p=0 ip=-1 icnt=0 while True: icnt+=1 if icnt>50: break ip+=1 p1=0 yn="" for i in range(h): q=deque() for j2 in range(w-k+1): for j3 in range(j2+1,j2+k): if a[i][j2]==0 or a[i][j2]!=a[i][j3]: break q.append((j2,a[i][j2])) yn="yes" # print("i:",i,q) jm=-2 while len(q)>0: j2,aij=q.popleft() for j3 in range(j2,j2+k): a[i][j3]=0 # print("j2:",j2,"jm+1:",jm+1) if j2!=jm+1: p1+=aij*k else: p1+=aij jm=j2 # print("p1:",p1) # print("1:",a) # print("2:",a) for jj in range(w): for ii in range(h): if a[ii][jj]==0: for iii in range(ii+1,h): if a[iii][jj]!=0: a[ii][jj]=a[iii][jj] a[iii][jj]=0 break # print(yn,a) p+=p1*(2**ip) if yn!="yes": # print(p,p1,ip) break # print("---------------------") pmax=max(pmax,p) # print(a) print(pmax)
s777912848
p03930
u723711163
1594428398
Python
PyPy3 (7.3.0)
py
Runtime Error
112
74428
997
from itertools import groupby def calc(): s = 0 for i in range(h): gr = groupby(g[i]) j = 0 for key,it in gr: l = len(list(it)) j += l if key==-1: continue if l >= K: g[i][j:j+l] = [-1]*l # for k in range(l): # g[i][j+k] = -1 # # print("s", key, l, key*l) s += key*l return s def flatten(): for j in range(w): lst = [] for i in range(h-1, -1, -1): if g[i][j] > 0: lst.append(g[i][j]) lst += [-1] * (h - len(lst)) for i in range(h-1, -1, -1): g[i][j] = lst[h-i-1] h,w,K = map(int,input().split()) mat = [ [int(e) for e in list(input())] for _ in range(h) ] res = 0 for i in range(h): for j in range(w): score = 0 g = [ [ mat[n][m] for m in range(w) ] for n in range(h) ] g[i][j] = -1 time = 0 flatten() while True: s = calc(time) if s==0: break score += s flatten() time += 1 res = max(res, score) print(res)
s860168289
p03930
u366625467
1593627456
Python
PyPy3 (7.3.0)
py
Runtime Error
339
77220
1635
from copy import deepcopy h,w,border=map(int,input().split()) G_original=[] for i in range(w): L=list(str(input())) for j in range(len(L)): L[j]=int(L[j]) G_original.append(L) def delete(row): #圧縮 L=[] temp=[row[0],1] for i in range(len(row)-1): if row[i]==row[i+1]: temp[1]+=1 else: L.append(temp) temp=[row[i+1],1] L.append(temp) res=0 index=-1 for i in range(len(L)): if L[i][0]>=1 and L[i][1]>=border: for j in range(index+1,index+L[i][1]+1): row[j]=-1 res+=L[i][0]*L[i][1] index+=L[i][1] else: index+=L[i][1] return res,row #ans=delete([1,2,2,2,2,5,2,3,3,3,1]) #print(ans) ans=0 for i in range(h): for j in range(w): #必要か G=deepcopy(G_original) temp=0 G[i][j]=-1 count=-1 while True: for k in range(w): res=[] for l in range(h)[::-1]: if G[l][k]>=1: res.append(G[l][k]) if len(res)<w: res+=[-1]*(w-len(res)) for l in range(h): G[l][k]=res[h-l-1] #print(G) count+=1 flag=True for k in range(h): now,G[k]=delete(G[k]) if now>0: temp+=(2**count)*now flag=False #print(temp,G) if flag: break ans=max(ans,temp) print(ans)
s305970622
p03930
u366625467
1593627010
Python
Python (3.8.2)
py
Runtime Error
1103
9260
1635
from copy import deepcopy h,w,border=map(int,input().split()) G_original=[] for i in range(w): L=list(str(input())) for j in range(len(L)): L[j]=int(L[j]) G_original.append(L) def delete(row): #圧縮 L=[] temp=[row[0],1] for i in range(len(row)-1): if row[i]==row[i+1]: temp[1]+=1 else: L.append(temp) temp=[row[i+1],1] L.append(temp) res=0 index=-1 for i in range(len(L)): if L[i][0]>=1 and L[i][1]>=border: for j in range(index+1,index+L[i][1]+1): row[j]=-1 res+=L[i][0]*L[i][1] index+=L[i][1] else: index+=L[i][1] return res,row #ans=delete([1,2,2,2,2,5,2,3,3,3,1]) #print(ans) ans=0 for i in range(h): for j in range(w): #必要か G=deepcopy(G_original) temp=0 G[i][j]=-1 count=-1 while True: for k in range(w): res=[] for l in range(h)[::-1]: if G[l][k]>=1: res.append(G[l][k]) if len(res)<w: res+=[-1]*(w-len(res)) for l in range(h): G[l][k]=res[h-l-1] #print(G) count+=1 flag=True for k in range(h): now,G[k]=delete(G[k]) if now>0: temp+=(2**count)*now flag=False #print(temp,G) if flag: break ans=max(ans,temp) print(ans)
s588442805
p03930
u638795007
1583710719
Python
PyPy3 (2.4.0)
py
Runtime Error
1040
71584
7853
def ABC120_D(): class UnionFind(): def __init__(self, n): self.parent = [-1 for _ in range(n)] # 正==子: 根の頂点番号 / 負==根: 連結頂点数 def find(self, x): # 要素xが属するグループの根を返す if self.parent[x] < 0: return x else: self.parent[x] = self.find(self.parent[x]) return self.parent[x] def unite(self, x, y): # 要素xが属するグループと要素yが属するグループとを併合する x, y = self.find(x), self.find(y) if x == y: return False else: if self.size(x) < self.size(y): x, y = y, x self.parent[x] += self.parent[y] self.parent[y] = x def same(self, x, y): # 要素x, yが同じグループに属するかどうかを返す return self.find(x) == self.find(y) def size(self, x): # 要素xが属するグループのサイズ(要素数)を返す x = self.find(x) return -self.parent[x] def is_root(self, x): # 要素の根をリストで返す return self.parent[x] < 0 def roots(self): # すべての根の要素をリストで返す return [i for i, x in enumerate(self.parent) if x < 0] def members(self, x): # 要素xが属するグループに属する要素をリストで返す root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def group_count(self): # グループの数を返す return len(self.roots()) def all_group_members(self): # {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す return {r: self.members(r) for r in self.roots()} N, M = LI() P = [[]for _ in range(M)] for i in range(M): P[i] = LI() uf = UnionFind(N) ans = [N*(N-1)//2]*M for i,[a,b] in enumerate(P[M-1:0:-1]): #print(i,a,b) a -= 1; b -= 1 if uf.same(a,b): ans[i+1] = ans[i] else: cur = uf.size(a)*uf.size(b) ans[i+1] = ans[i]-cur uf.unite(a,b) for v in ans[::-1]: print(v) return def JOI8_1(): N = I() C = [I()for _ in range(N)] prev = C[0] BW = [[1,prev]] for i in range(1,N): #print(BW) if BW[-1][1]==C[i]: BW[-1][0] += 1 else: if i%2==0: BW.append([1,C[i]]) else: if len(BW) > 1: BW[-2][0] += (BW[-1][0] + 1) del BW[-1] else: BW[0][0] += 1 BW[0][1] = C[i] ans = 0 #print(BW) for i,s in BW: if s==0: ans += i print(ans) return """ 8 1 0 1 1 0 0 0 1 """ def JOI13_A(): N = I() A = LI() S = [] cur = 1 prev = A[0] for i in range(1,N): if prev^A[i]==1: cur += 1 else: S.append(cur) cur = 1 prev = A[i] if cur>0: S.append(cur) #print(S) ans = 0 for i in range(len(S)-2): cur = S[i]+S[i+1]+S[i+2] if ans<cur: ans = cur if len(S)<=2: ans = N print(ans) return """ 10 1 1 0 0 1 0 1 1 1 0 """ def square869120Contest5_B(): def length(a,b): return ((a[0]-b[0])**2 + (a[1]-b[1])**2)**0.5 def check(r): for i in range(M): for j in range(N): if length(X[i],A[j][0:2])<A[j][2]+r+_ep: return False for j in range(M): if i==j: continue if length(X[i],X[j])<r+r+_ep: return False return True N, M = LI() A = [LI()for _ in range(N)] X = [LI()for _ in range(M)] minA = inf for i,j,a in A: if minA>a: minA = a l = 0; r = 200 while(r-l>_ep): now = (l+r)/2 if check(now): l = now else: r = now ans = min(l,minA) print(ans) return def ABC144_D(): a, b, x = LI() half = a*a*b/2 if x>=half: y = (half*2-x)/(a*a/2) deg = math.atan2(a,y) #print(y,a,deg) ans = 90-deg*180/math.pi else: y = x/(a*b/2) deg = math.atan2(b,y) ans = deg*180/math.pi print(ans) return def square869120Contest3_B(): def check_del(S): sco = 0 for h in range(H): for w in range(W-K+1): s = S[h][w] if s==0: continue if K==3 and s==S[h][w+1] and s==S[h][w+2]: d = 3 for k in range(W-K+1-w): if S[h][w]!=S[h][w+2+k]: break d += 1 t = S[h][w] sco += cal_score(t,d) del_stone(S,h,w,d) elif K==2 and s==S[h][w+1]: d = 2 for k in range(W-K-w): if S[h][w]!=S[h][w+2+k]: break d += 1 t = S[h][w] sco += cal_score(t,d) del_stone(S,h,w,d) return sco,S def del_stone(S,y,x,k): for i in range(k): S[y][x+i] = 0 return S def cal_score(t,c): return (2**now)*(t*c) def move_stone(S): rep = deepcopy(S) for w in range(W): blank = -1 que = deque() for h in range(H)[::-1]: if rep[h][w]==0: if blank==-1: blank = h else: if blank>=0: que.append(rep[h][w]) rep[h][w] = 0 if blank==-1: continue for h,i in enumerate(que): rep[blank-h][w] = i return rep H, W, K = LI() A = [SI()for _ in range(H)] C = [[]for _ in range(H)] for h in range(H): for w in range(W): C[h].append(int(A[h][w])) if K>=4: print(0) return ans = 0 if K==1: for c in C: ans += sum(c) print(ans) return for h in range(H): for w in range(W): nowC = deepcopy(C) nowC[h][w] = 0 #print(nowC) cur = 0 now = 0 while(True): nowC = move_stone(nowC) #print(nowC) rep,nowC = check_del(nowC) #print(nowC) #print() if rep==0: break cur += rep now += 1 #print(h,w,cur) if ans<cur: ans = cur print(ans) return import sys,bisect,itertools,heapq,math,random from copy import deepcopy from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod,mod2,inf,alphabet,_ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = 10**(-12) alphabet = [chr(ord('a') + i) for i in range(26)] sys.setrecursionlimit(10**6) if __name__ == '__main__': square869120Contest3_B() """ """
s753670710
p03930
u638795007
1583710366
Python
Python (3.4.3)
py
Runtime Error
1056
4720
7760
def ABC120_D(): class UnionFind(): def __init__(self, n): self.parent = [-1 for _ in range(n)] # 正==子: 根の頂点番号 / 負==根: 連結頂点数 def find(self, x): # 要素xが属するグループの根を返す if self.parent[x] < 0: return x else: self.parent[x] = self.find(self.parent[x]) return self.parent[x] def unite(self, x, y): # 要素xが属するグループと要素yが属するグループとを併合する x, y = self.find(x), self.find(y) if x == y: return False else: if self.size(x) < self.size(y): x, y = y, x self.parent[x] += self.parent[y] self.parent[y] = x def same(self, x, y): # 要素x, yが同じグループに属するかどうかを返す return self.find(x) == self.find(y) def size(self, x): # 要素xが属するグループのサイズ(要素数)を返す x = self.find(x) return -self.parent[x] def is_root(self, x): # 要素の根をリストで返す return self.parent[x] < 0 def roots(self): # すべての根の要素をリストで返す return [i for i, x in enumerate(self.parent) if x < 0] def members(self, x): # 要素xが属するグループに属する要素をリストで返す root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def group_count(self): # グループの数を返す return len(self.roots()) def all_group_members(self): # {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す return {r: self.members(r) for r in self.roots()} N, M = LI() P = [[]for _ in range(M)] for i in range(M): P[i] = LI() uf = UnionFind(N) ans = [N*(N-1)//2]*M for i,[a,b] in enumerate(P[M-1:0:-1]): #print(i,a,b) a -= 1; b -= 1 if uf.same(a,b): ans[i+1] = ans[i] else: cur = uf.size(a)*uf.size(b) ans[i+1] = ans[i]-cur uf.unite(a,b) for v in ans[::-1]: print(v) return def JOI8_1(): N = I() C = [I()for _ in range(N)] prev = C[0] BW = [[1,prev]] for i in range(1,N): #print(BW) if BW[-1][1]==C[i]: BW[-1][0] += 1 else: if i%2==0: BW.append([1,C[i]]) else: if len(BW) > 1: BW[-2][0] += (BW[-1][0] + 1) del BW[-1] else: BW[0][0] += 1 BW[0][1] = C[i] ans = 0 #print(BW) for i,s in BW: if s==0: ans += i print(ans) return """ 8 1 0 1 1 0 0 0 1 """ def JOI13_A(): N = I() A = LI() S = [] cur = 1 prev = A[0] for i in range(1,N): if prev^A[i]==1: cur += 1 else: S.append(cur) cur = 1 prev = A[i] if cur>0: S.append(cur) #print(S) ans = 0 for i in range(len(S)-2): cur = S[i]+S[i+1]+S[i+2] if ans<cur: ans = cur if len(S)<=2: ans = N print(ans) return """ 10 1 1 0 0 1 0 1 1 1 0 """ def square869120Contest5_B(): def length(a,b): return ((a[0]-b[0])**2 + (a[1]-b[1])**2)**0.5 def check(r): for i in range(M): for j in range(N): if length(X[i],A[j][0:2])<A[j][2]+r+_ep: return False for j in range(M): if i==j: continue if length(X[i],X[j])<r+r+_ep: return False return True N, M = LI() A = [LI()for _ in range(N)] X = [LI()for _ in range(M)] minA = inf for i,j,a in A: if minA>a: minA = a l = 0; r = 200 while(r-l>_ep): now = (l+r)/2 if check(now): l = now else: r = now ans = min(l,minA) print(ans) return def ABC144_D(): a, b, x = LI() half = a*a*b/2 if x>=half: y = (half*2-x)/(a*a/2) deg = math.atan2(a,y) #print(y,a,deg) ans = 90-deg*180/math.pi else: y = x/(a*b/2) deg = math.atan2(b,y) ans = deg*180/math.pi print(ans) return def square869120Contest3_B(): def check_del(S): sco = 0 for h in range(H): for w in range(W-K+1): s = S[h][w] if s==0: continue if K==3 and s==S[h][w+1] and s==S[h][w+2]: d = 3 for k in range(W-K+1-w): if S[h][w]!=S[h][w+2+k]: break d += 1 t = S[h][w] sco += cal_score(t,d) del_stone(S,h,w,d) elif K==2 and s==S[h][w+1]: d = 2 for k in range(W-K-w): if S[h][w]!=S[h][w+2+k]: break d += 1 t = S[h][w] sco += cal_score(t,d) del_stone(S,h,w,d) return sco,S def del_stone(S,y,x,k): for i in range(k): S[y][x+i] = 0 return S def cal_score(t,c): return (2**now)*(t*c) def move_stone(S): rep = deepcopy(S) for w in range(W): blank = -1 que = deque() for h in range(H)[::-1]: if rep[h][w]==0: if blank==-1: blank = h else: if blank>=0: que.append(rep[h][w]) rep[h][w] = 0 if blank==-1: continue for h,i in enumerate(que): rep[blank-h][w] = i return rep H, W, K = LI() A = [SI()for _ in range(H)] C = [[]for _ in range(H)] for h in range(H): for w in range(W): C[h].append(int(A[h][w])) if K>=4: print(0) return ans = 0 for h in range(H): for w in range(W): nowC = deepcopy(C) nowC[h][w] = 0 #print(nowC) cur = 0 now = 0 while(True): nowC = move_stone(nowC) #print(nowC) rep,nowC = check_del(nowC) #print(nowC) #print() if rep==0: break cur += rep now += 1 #print(h,w,cur) if ans<cur: ans = cur print(ans) return import sys,bisect,itertools,heapq,math,random from copy import deepcopy from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod,mod2,inf,alphabet,_ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = 10**(-12) alphabet = [chr(ord('a') + i) for i in range(26)] sys.setrecursionlimit(10**6) if __name__ == '__main__': square869120Contest3_B() """ """
s598591376
p03930
u966695411
1479706744
Python
Python (3.4.3)
py
Runtime Error
24
3192
1113
#! /usr/bin/env python3 def dropcell(): for y in range(H): for i in range(H): for j in range(W): if gm[H-i][j] == 0: gm[H-i-1][j], gm[H-i][j] = gm[H-i][j], gm[H-i-1][j] def removecell(): global gp, gf gf = False p = 0 for y in range(H): c = 1 t = 0 for i in range(W+1): x = gm[y+1][i] if x > 0 and x == t: c += 1 else: if c >= K: for j in range(c): gm[y+1][i-1-j] = 0 p += (t * c) gf = True t = x c = 1 gp += p * (2**gi) H, W, K = map(int, input().split()) M = [[0]*(W+1)]+[list(map(int, [*input()]))+[0] for i in range(H)] points = {} for i in range(H)[::-1]: for j in range(W): gp = 0 gf = True gi = 0 gm = [[j for j in i]for i in M] gm[i+1][j] = 0 while gf: dropcell() removecell() gi += 1 points[gp] = 1 print(max(points))
s418394272
p03930
u118800894
1479701503
Python
Python (2.7.6)
py
Runtime Error
17
2824
1346
def main(): h, w, k = map(int, raw_input().split()) c = [map(int, raw_input().strip()) for _ in xrange(h)] def go(a): if not res: return 0 return go(a) * 2 + res ans = 0 for ii in xrange(h): for jj in xrange(w): a = [c[i][:] for i in xrange(h)] a[ii][jj] = 0 r = 0 e = 1 while res: for j in xrange(w): st = [a[i][j] for i in xrange(h) if a[i][j]] for i in xrange(h): a[i][j] = 0 i = -1 for x in reversed(st): a[i][j] = x i -= 1 res = 0 for i in xrange(h): j = 0 while j < w: t = j + 1 while t < w and a[i][j] == a[i][t]: t += 1 if t - j >= k: for j in xrange(j, t): res += a[i][j] a[i][j] = 0 j = t if not res: break r += res * e e *= 2 if ans < r: ans = r print ans main()
s427661328
p03931
u644325407
1479692793
Python
PyPy3 (2.4.0)
py
Runtime Error
471
44636
578
#!/usr/bin/env pypy3 import functools import itertools import math import operator P = 1000000007 def xors(seq): return functools.reduce(operator.xor, seq) def solve(n, k, xs): l = len(xs) a = 0 for i in range(1, l + 1): for ys in itertools.combinations(xs, i): if xors(ys) == k: a += math.factorial(i) a %= P return a def main(): n, k = map(int, input().split()) assert n <= 20 xs = [int(x) for x in input().split()] print(solve(n, k, xs)) if __name__ == '__main__': main()
s139163136
p03932
u296290704
1527216041
Python
PyPy3 (2.4.0)
py
Runtime Error
2112
123912
772
H, W = map(int, input().split()) A = [list(map(int, input().split())) for i in range(H)] if H <= 2 or W <= 2: print(sum(map(sum, A))) exit(0) def solve(A, W, H): S = {(0, 1): 0} for c in range(1, H-1): T = {} for p, q in S: v = S[p, q] + A[c-p][p] + A[c-q][q] T[p, q] = max(T.get((p, q), 0), v) if p+1 < q: T[p+1, q] = max(T.get((p+1, q), 0), v) if q+1 < W: T[p, q+1] = max(T.get((p, q+1), 0), v) T[p+1, q+1] = max(T.get((p+1, q+1), 0), v) S = T return S B = [e[::-1] for e in A[::-1]] S0 = solve(A, W, H) S1 = solve(B, H, W) print(A[0][0] + A[-1][-1] + max(S0[p, q] + S1[H-1-q, H-1-p] + A[H-1-p][p] + A[H-1-q][q] for p, q in S0))
s289502671
p03932
u296290704
1527215947
Python
PyPy3 (2.4.0)
py
Runtime Error
2112
155268
792
H, W = map(int, input().split()) A = [list(map(int, input().split())) for i in range(H)] if H <= 2 or W <= 2: print(sum(map(sum, A))) exit(0) def solve(A, W, H): S = {(0, 1): 0} for c in range(1, H-1): T = {} for p, q in S: v = S[p, q] + A[c-p][p] + A[c-q][q] T[p, q] = max(T.get((p, q), 0), v) if p+1 < q: T[p+1, q] = max(T.get((p+1, q), 0), v) if q+1 < W: T[p, q+1] = max(T.get((p, q+1), 0), v) T[p+1, q+1] = max(T.get((p+1, q+1), 0), v) S = T print(c, S) return S B = [e[::-1] for e in A[::-1]] S0 = solve(A, W, H) S1 = solve(B, H, W) print(A[0][0] + A[-1][-1] + max(S0[p, q] + S1[H-1-q, H-1-p] + A[H-1-p][p] + A[H-1-q][q] for p, q in S0))
s057167488
p03932
u296290704
1527136266
Python
Python (3.4.3)
py
Runtime Error
2108
92076
592
H, W = map(int, input().split()) A = [list(map(int, input().split())) for i in range(H)] memo = {(W+H-2, H-2, H-1): 0} def dfs(c, p, q): if (c, p, q) in memo: return memo[c, p, q] res = 0 if c+1-W < p < q < H: res = max(res, dfs(c+1, p, q)) if c+1-W < p+1 < q < H: res = max(res, dfs(c+1, p+1, q)) if c+1-W < p < q+1 < H: res = max(res, dfs(c+1, p, q+1)) if c+1-W < p+1 < q+1 < H: res = max(res, dfs(c+1, p+1, q+1)) memo[c, p, q] = res = res + A[c-p][p] + A[c-q][q] return res print(dfs(1, 0, 1) + A[0][0] + A[-1][-1])
s033617138
p03937
u394244719
1599427310
Python
Python (3.8.2)
py
Runtime Error
30
9340
1628
import sys inint = lambda: int(sys.stdin.readline()) inintm = lambda: map(int, sys.stdin.readline().split()) inintl = lambda: list(inintm()) instrm = lambda: map(str, sys.stdin.readline().split()) instrl = lambda: list(instrm()) h, w = inintm() grid = [] now = [0,0] fw = 0 fh = 0 for i in range(h): grid.append(input()) while now != [h-1,w-1]: if now[0] == h-1: if fh == 0 and now[1] != 0: if grid[h-1][now[1]+1] == "#" and grid[h-1][now[1]-1] == ".": now = [h-1, now[1]+1] fh = 1 else: if grid[h-1][now[1]+1] == "#": now = [h-1, now[1]+1] fh = 1 else: print("Impossible") exit() elif now[1] == w-1: if fw == 0 and now[0] != 0: if grid[now[0]+1][w-1] == "#" and grid[now[0]-1][w-1] == ".": now = [now[0]+1, w-1] fw = 1 else: print("Impossible") exit() else: if grid[now[0]+1][w-1] == "#": now = [now[0]+1, w-1] fw = 1 else: print("Impossible") exit() else: if grid[now[0]+1][now[1]] == "#" and grid[now[0]][now[1]+1] == ".": now = [now[0]+1, now[1]] elif grid[now[0]+1][now[1]] == "." and grid[now[0]][now[1]+1] == "#": now = [now[0], now[1]+1] else: print("Impossible") exit() if fh == 0 and grid[h-1, w-2] == "#" and (h >= 2 and w >= 2): print("Impossible") exit() print("Possible")
s360465067
p03937
u394244719
1599427087
Python
Python (3.8.2)
py
Runtime Error
26
9168
1604
import sys inint = lambda: int(sys.stdin.readline()) inintm = lambda: map(int, sys.stdin.readline().split()) inintl = lambda: list(inintm()) instrm = lambda: map(str, sys.stdin.readline().split()) instrl = lambda: list(instrm()) h, w = inintm() grid = [] now = [0,0] fw = 0 fh = 0 for i in range(h): grid.append(input()) while now != [h-1,w-1]: if now[0] == h-1: if fh == 0 and now[1] != 0: if grid[h-1][now[1]+1] == "#" and grid[h-1][now[1]-1] == ".": now = [h-1, now[1]+1] fh = 1 else: if grid[h-1][now[1]+1] == "#": now = [h-1, now[1]+1] fh = 1 else: print("Impossible") exit() elif now[1] == w-1: if fw == 0 and now[0] != 0: if grid[now[0]+1][w-1] == "#" and grid[now[0]-1][w-1] == ".": now = [now[0]+1, w-1] fw = 1 else: print("Impossible") exit() else: if grid[now[0]+1][w-1] == "#": now = [now[0]+1, w-1] fw = 1 else: print("Impossible") exit() else: if grid[now[0]+1][now[1]] == "#" and grid[now[0]][now[1]+1] == ".": now = [now[0]+1, now[1]] elif grid[now[0]+1][now[1]] == "." and grid[now[0]][now[1]+1] == "#": now = [now[0], now[1]+1] else: print("Impossible") exit() if fh == 0 and grid[h-1, w-2] == "#": print("Impossible") exit() print("Possible")
s896466307
p03937
u867826040
1599275084
Python
Python (3.8.2)
py
Runtime Error
29
8784
408
#define rep(i,n) for (int i = 0; i < (int)(n); i++) #include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); short h,w,ans = 0; cin >> h >> w; char ai[10]; rep(i,h) { cin >> ai; rep(j,8) if (ai[j] == '#') ans ++; } if (ans == h+w-1) cout << "Possible\n"; else cout << "Impossible\n"; }
s388445803
p03937
u022215787
1595020281
Python
Python (3.8.2)
py
Runtime Error
26
9012
2025
h, w = map(int, input().split()) mat_a = [ list(input()) for _ in range(h) ] ans = 'Possible' ans = 'Impossible' def check(i,j): if mat_a[i][j] == '.': return True count = 0 try: if mat_a[i][j-1] == '#': count += 1 except: pass try: if mat_a[i-1][j] == '#': count += 1 except: pass try: if mat_a[i][j+1] == '#': count += 1 except: pass try: if mat_a[i+1][j] == '#': count += 1 except: pass if count == 2 or count ==4: return True else: return False ans = True for i in range(h): for j in range(w): if not check(i,j): if i+1 == h and j+1 == w: continue if i == 0 and j == 0: continue ans = False break if ans: print('Possible') else: print('Impossible') (env3) (kentaro:~/git/2020/atcode/20200717/3 2020-07-17T17:09:31)$ vi main.py (env3) (kentaro:~/git/2020/atcode/20200717/3 2020-07-17T17:10:52)$ cat main.py h, w = map(int, input().split()) mat_a = [ list(input()) for _ in range(h) ] def check(i,j): if mat_a[i][j] == '.': return True count = 0 try: if mat_a[i][j-1] == '#': count += 1 except: pass try: if mat_a[i-1][j] == '#': count += 1 except: pass try: if mat_a[i][j+1] == '#': count += 1 except: pass try: if mat_a[i+1][j] == '#': count += 1 except: pass if count == 2 or count == 4: return True else: return False ans = True for i in range(h): for j in range(w): if not check(i,j): if i+1 == h and j+1 == w: continue if i == 0 and j == 0: continue ans = False break if ans: print('Possible') else: print('Impossible')
s088063624
p03937
u247211039
1595020186
Python
Python (3.8.2)
py
Runtime Error
24
9128
408
H,W=4,5 a = [input() for i in range(H)] ans=0 cnt=0 for i in range(H-1): for j in range(W-1): if a[i][j] == '#' and a[i+1][j] == '#' and a[i][j+1] == '#': cnt+=1 break elif a[i][j] == '#' and a[i+1][j] == '.' and a[i][j+1] == '.': cnt+=1 break else: continue print('Impossible' if cnt>0 else 'Possible')
s477707604
p03937
u629350026
1594086354
Python
Python (3.8.2)
py
Runtime Error
31
8944
458
h,w=map(int,input().split()) a=[] for i in range(h): at=list(str(input())) a.append(at) i=0 j=0 t=0 while True: if a[i][j+1]=="#": for k in range(i+1,h): if a[k][j]=="#": t=1 break else: j=j+1 elif a[i+1][j]=="#": for k in range(j+1,w): if a[i][k]=="#": t=1 break else: i=i+1 if t==1: print("Impossible") break elif i==h-1 and j==w-1: print("Possible") break
s657084323
p03937
u535803878
1594079109
Python
PyPy3 (7.3.0)
py
Runtime Error
84
74716
734
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") h,w = map(int, input().split()) a = [None]*h for i in range(h): a[i] = input() cx = 0 cy = 0 d = set() while (cx,cy)!=(h-1, w-1): val = 0 # print(cx,cy) for dx, dy in [(1,0), (0,1)]: ccx = cx+dx ccy = cy+dy if ccx>=h or ccy>=w or a[ccx][ccy]==".": continue nx, ny = ccx, ccy val += 1 if val>=2 or val==0: ans = "Impossible" break cx, cy = nx, ny else: vv = sum(item=="#" for item in items for items in a) if vv==h+w-1: ans = "Possible" else: ans = "Impossible" print(ans)
s749441363
p03937
u277429554
1593411362
Python
Python (3.8.2)
py
Runtime Error
29
8980
214
h, w = map(int,input().split()) a = [list(input()) for _ in range(H)] c = 0 for p in a : for q in p: if q=="#": c +=1 if c == h + w - 1: print("Possible") else: print("Impossible")
s847879746
p03937
u075304271
1593221718
Python
Python (3.8.2)
py
Runtime Error
31
9100
525
def solve(): h, w = map(int, input().split()) a = [list(input()) for _ in range(h)] for i in range(h-1): for j in range(w-1): if a[i][j:j+2] == ["#","#"]: if a[i+1][j] == '#': print("Impossible") exit() if a[i][j:j+3] == ["#","#","#"] and w > 2: if a[i+2][j] == '#': print("Impossible") exit() print("Possible") return 0 if __name__ == "__main__": solve()
s384473553
p03937
u075304271
1593221686
Python
Python (3.8.2)
py
Runtime Error
30
9132
525
def solve(): h, w = map(int, input().split()) a = [list(input()) for _ in range(h)] for i in range(h-1): for j in range(w-1): if a[i][j:j+2] == ["#","#"]: if a[i+1][j] == '#': print("Impossible") exit() if a[i][j:j+3] == ["#","#","#"] and n > w: if a[i+2][j] == '#': print("Impossible") exit() print("Possible") return 0 if __name__ == "__main__": solve()
s726612568
p03937
u075304271
1593221658
Python
Python (3.8.2)
py
Runtime Error
31
9168
515
def solve(): h, w = map(int, input().split()) a = [list(input()) for _ in range(h)] for i in range(h-1): for j in range(w-1): if a[i][j:j+2] == ["#","#"]: if a[i+1][j] == '#': print("Impossible") exit() if a[i][j:j+3] == ["#","#","#"]: if a[i+2][j] == '#': print("Impossible") exit() print("Possible") return 0 if __name__ == "__main__": solve()
s664021741
p03937
u827202523
1593220211
Python
PyPy3 (7.3.0)
py
Runtime Error
96
74860
1365
import sys from collections import defaultdict, deque, Counter import math # import copy from bisect import bisect_left, bisect_right # import heapq # sys.setrecursionlimit(1000000) # input aliases input = sys.stdin.readline getS = lambda: input().strip() getN = lambda: int(input()) getList = lambda: list(map(int, input().split())) getZList = lambda: [int(x) - 1 for x in input().split()] INF = 10 ** 20 MOD = 10**9 + 7 divide = lambda x: pow(x, MOD-2, MOD) def solve(): n, m = getList tmp = 0 for i in range(n): s = getS() stop = False for i, c in enumerate(s): if i < tmp: if c == "#": print("Impossible") return else: if not stop: if c == ".": stop = True tmp = i-1 else: if c == "#": print("Impossible") return print("Possible") return nums = getList() ans = 0 for i, num in enumerate(nums): ans += 2 * (min(abs(k - num), num)) print(ans) def main(): n = getN() for _ in range(n): solve() if __name__ == "__main__": # main() solve()
s814875384
p03937
u593567568
1592446549
Python
Python (3.4.3)
py
Runtime Error
18
3064
441
H,W = map(int,input().split()) GRID = [list(input()) for _ in range(H)] def dfs(h,w,c): if h == H - 1 and w == W - 1: return c + 1 if GRID[h][w] != "#": return 0 if H - 1 < h or W -1 < w: return 0 right = dfs(h+1,w,c+1) down = dfs(h,w+1,c+1) c += max(right,down) return c NUM = sum([GRID[x].count("#") for x in range(H)]) n = dfs(0,0,0) if n == NUM: print("Possible") else: print("Impossible")
s866032935
p03937
u157232135
1591639677
Python
Python (3.4.3)
py
Runtime Error
18
3064
579
def main(): h,w=map(int,input().split()) a=[] for _ in range(h): a.append(input()) now = [0, 0] end = [h-1, w-1] while now != end: nxt = None if now[0]+1 < len(a) and a[now[0]+1][now[1]] == "#": nxt = now[:] nxt[0] += 1 if now[1]+1 < len(a[now[0]]) and a[now[0]][now[1]+1] == "#": if nxt != None: print("Impossible") return nxt = now[:] nxt[1] += 1 now = nxt print("Possible") if __name__ == "__main__": main()
s101891186
p03937
u227085629
1591140744
Python
Python (3.4.3)
py
Runtime Error
17
3064
347
h,w = map(int,input().split()) a = [list(input()) for nesya in range(h)] b = [['.']*w for motsu in range(h)] b[0][0] = '#' j = 0 for i in range(h): if j < w: while a[i][j+1] == '#': j += 1 b[i][j] = '#' if j == w-1: break if i+1 < h: b[i+1][j] = '#' if a == b: print('Possible') else: print('Impossible')
s657645070
p03937
u227085629
1591140357
Python
Python (3.4.3)
py
Runtime Error
18
3064
279
h,w = map(int,input().split()) a = [list(input()) for nesya in range(h)] b = [['.']*w for motsu in range(h)] b[0][0] = '#' j = 0 for i in range(h): while a[i][j+1] == '#': j += 1 b[i][j] = '#' b[i+1][j] = '#' if a == b: print('Possible') else: print('Impossible')
s674100173
p03937
u922449550
1590080124
Python
Python (3.4.3)
py
Runtime Error
18
3064
579
H, W = map(int, input().split()) A = [input() for i in range(H)] visited = [[False]*W for i in range(H)] visited[0][0] = True d = [[0, 0], [-1, -1]] while d: x, y, px, py = d.pop() num = 0 flag = False for dx, dy in [[1, 0], [0, 1], [-1, 0], [0, -1]]: if 0<=x+dx<H and 0<=y+dy<W and [x+dx, y+dy]!=[px, py] and A[x+dx][y+dy]=='#' and not visited[x+dx][y+dy]: visited[x+dx][y+dy] = True num += 1 d.append([x+dx, y+dy, x, y]) if dx < 0 or dy < 0: flag = True if (num >= 2) or flag: print('Impossible') quit() print('Possible')
s547431986
p03937
u268516119
1589683227
Python
PyPy3 (2.4.0)
py
Runtime Error
177
38384
141
H, W = [int(hoge) for hoge in input().split()] print(Possible) if sum([input().count("#") for h in range(H)]) == H+W-1 else print(Impossible)
s861409389
p03937
u652656291
1589377721
Python
Python (3.4.3)
py
Runtime Error
18
3060
270
h,w = map(int,input().split()) HW = [list(map(str,input().split())) for _ in range(h)] sharp = 0 for i in range(w): for j in range(h): if HW[i][j] == '#': sharp += 1 min_root = h + w - 1 if sharp == min_root: print('Possible') else: print('Impossible')
s869028213
p03937
u652656291
1589377589
Python
Python (3.4.3)
py
Runtime Error
18
2940
178
h,w = map(int,input().split()) HW = [list(map(int,input().split())) for _ in range(h)] min_root = h + w - 1 if sharp == min_root: print('Possible') else: print('Impossible')
s171880776
p03937
u652656291
1589377558
Python
Python (3.4.3)
py
Runtime Error
17
3056
199
h,w = map(int,input().split()) HW = [list(map(int,input().split())) for _ in range(h)] sharp = HW.count('#') min_root = h + w - 1 if sharp == min_root: print('Possible') else: print('Impossible')
s805927205
p03937
u829249049
1588465559
Python
Python (3.4.3)
py
Runtime Error
17
3064
669
import sys H,W=map(int,input().split()) listA=[list(input()) for i in range(H)] start=[0,0] while 1: if start==[H-1,W-1]: print("Possible") sys.exit() if start[0]!=H-1 and listA[start[0]+1][start[1]]=="#" and listA[start[0]][start[1]+1]=="#": print("Impossible") sys.exit() if start[0]!=0 and start[1]!=0 and listA[start[0]-1][start[1]]=="#" and listA[start[0]][start[1]-1]=="#": print("Impossible") sys.exit() if start[0]!=H-1 and listA[start[0]+1][start[1]]=="#": start=[start[0]+1,start[1]] continue if start[1]!=W-1 and listA[start[0]][start[1]+1]=="#": start=[start[0],start[1]+1] else: print("Impossible")
s417841313
p03937
u829249049
1588465453
Python
Python (3.4.3)
py
Runtime Error
18
3064
658
H,W=map(int,input().split()) listA=[list(input()) for i in range(H)] start=[0,0] while 1: if start==[H-1,W-1]: print("Possible") sys.exit() if start[0]!=H-1 and listA[start[0]+1][start[1]]=="#" and listA[start[0]][start[1]+1]=="#": print("Impossible") sys.exit() if start[0]!=0 and start[1]!=0 and listA[start[0]-1][start[1]]=="#" and listA[start[0]][start[1]-1]=="#": print("Impossible") sys.exit() if start[0]!=H-1 and listA[start[0]+1][start[1]]=="#": start=[start[0]+1,start[1]] continue if start[1]!=W-1 and listA[start[0]][start[1]+1]=="#": start=[start[0],start[1]+1] else: print("Impossible")
s509586794
p03937
u829249049
1588465338
Python
Python (3.4.3)
py
Runtime Error
17
3064
651
import sys H,W=map(int,input().split()) listA=[list(input()) for i in range(H)] start=[0,0] while 1: if start==[H-1,W-1]: print("Possible") sys.exit() if start[0]!=H-1 and listA[start[0]+1][start[1]]=="#" and listA[start[0]][start[1]+1]=="#": print("Impossible") sys.exit() if start[0]!=0 and start[1]!=0 and listA[start[0]-1][start[1]]=="#" and listA[start[0]][start[1]-1]=="#": print("Impossible") sys.exit() if start[0]!=H-1 and listA[start[0]+1][start[1]]=="#": start=[start[0]+1,start[1]] continue if listA[start[0]][start[1]+1]=="#": start=[start[0],start[1]+1] else: print("Impossible")
s588903488
p03937
u829249049
1588464295
Python
Python (3.4.3)
py
Runtime Error
18
3188
765
import sys H,W=map(int,input().split()) listA=[list(input()) for i in range(H)] start=[0,0] while 1: if start==[H-1,W-1]: print("Possible") sys.exit() if start[1]==W-1 and start[0]!=H-1: print("Impossible") sys.exit() if start[0]!=H-1 and listA[start[0]+1][start[1]]=="#" and listA[start[0]][start[1]+1]=="#": print("Impossible") sys.exit() if start[0]!=0 and start[1]!=0 and listA[start[0]+1][start[1]]=="#" and listA[start[0]][start[1]-1]=="#" and listA[start[0]-1][start[1]]=="#": print("Impossible") sys.exit() if start[0]!=H-1 and listA[start[0]+1][start[1]]=="#": start=[start[0]+1,start[1]] continue if listA[start[0]][start[1]+1]=="#": start=[start[0],start[1]+1] else: print("Impossible")
s416370627
p03937
u276115223
1587989945
Python
Python (3.4.3)
py
Runtime Error
18
3064
599
# AGC 007: A – Shik and Stone H, W = [int(s) for s in input().split()] A = [input() for _ in range(H)] isExact = 'Possible' i, j = 0, 0 while i < H - 1 or j < W - 1: A[i] = A[i][:j] + '.' + A[i][j + 1:] if A[i + 1][j] != '#' and A[i][j + 1] != '#': isExact = 'Impossible' break if j + 1 < W and A[i][j + 1] == '#': j += 1 elif i + 1 < H and A[i + 1][j] == '#': i += 1 if isExact == 'Possible': A[H - 1] = A[H - 1][:W - 1] + '.' for line in A: if '#' in line: isExact = 'Impossible' break print(isExact)
s643944509
p03937
u726615467
1587297341
Python
Python (3.4.3)
py
Runtime Error
18
3064
754
H, W = map(int, input().split()) A = [list(input()) for _ in range(H)] i = j = 0 passed = [[None] * W for _ in range(H)] def dp(i, j): global H, W passed[i][j] = True if i == H - 1 and j == W - 1: return True # if i + 1 >= H: d = False else: d = (A[i + 1][j] == '#') # if j + 1 >= W: r = False else: r = (A[i][j + 1] == '#') # if d and not r: return dp(i + 1, j) elif not d and r: return dp(i, j + 1) else: return False if dp(0, 0): ans = 'Possible' for i in range(H): for j in range(W): if not visited[i][j] and A[i][j] == '#': ans = 'Impossible' # print(ans) else: print('Impossible')
s902511975
p03937
u545368057
1585657193
Python
Python (3.4.3)
py
Runtime Error
18
2940
190
H,W = map(int, input().split()) fields = [list(input()) for i in range(H)] for f in fields: cnt += f.count("#") if cnt == H + W - 1: print("Possible") else: print("Impossible")
s131942874
p03937
u185325486
1584971651
Python
Python (3.4.3)
py
Runtime Error
21
3316
441
from collections import deque H,W = map(int, input().split()) A = [input()+'.' for _ in range(H)] A.append('.'*(W+1)) total = sum([1 for a in A for s in a if s=='#']) que = deque([[0,0,1]]) while que: for x,y in [(1,0), (0,1)]: x_,y_,cnt = que.popleft() next_x, next_y = x_+x, y_+y if A[next_y][next_x] == '#': que.append([next_x,next_y,cnt+1]) print('Possible' if total == cnt else 'Impossible')
s129045826
p03937
u984276646
1584563244
Python
Python (3.4.3)
py
Runtime Error
17
3064
612
H, W = map(int, input().split()) pos = [[0, 0]] S = [input() for i in range(H)] p = 1 def whiteout(Map, h, w): y = 0 for i in range(h): for j in range(w): if Map[i][j] == '#': y += 1 return y == 0 while pos != [H-1, W-1]: cnt = 0 x, y = pos[0], pos[1] S[x] = S[x][:y] + '.' + S[x][y+1:] if x < H-1: if S[x+1][y] == '#': cnt += 1 pos = [x+1, y] if y < W-1: if S[x][y+1] == '#': cnt += 1 pos = [x, y+1] if cnt != 1: p = 0 break S[H-1] = S[H-1][:W-1] + '.' if p == 1 and whiteout(S, H, W): print("Possible") else: print("Impossible")
s970393637
p03937
u732870425
1584126553
Python
Python (3.4.3)
py
Runtime Error
18
3064
374
H, W = map(int, input().split()) A = [list(input().split()) for _ in range(H)] ans = "Impossible" d = [(1, 0), (0, 1)] def f(y, x): if y == H-1 and x == W-1: global ans ans = "Possible" return elif not (0 <= y < H and 0 <= x < W): return elif A[y][x] == ".": return f(y+1, x) f(y, x+1) f(0, 0) print(ans)
s594736202
p03937
u667024514
1584014091
Python
Python (3.4.3)
py
Runtime Error
17
2940
175
h,w=map(int,input().split()) num=0 s=[str(input()) for i in range(h):] for i in range(h): num+=s[i].count("#") if num>h+w-1: print("Impossible") exit() print("Possible")
s809096673
p03937
u073549161
1583476704
Python
Python (3.4.3)
py
Runtime Error
17
2940
604
maze = [] h, w = map(int,input().split()) for _ in range(h): maze.append(list(input())) #print(maze) x,y = 0,0 while True: maze[y][x] = "." if x == w-1 and y == h-1: break if x != w-1 and maze[y][x+1]== "#": x += 1 continue if y != h-1 and maze[y+1][x]=="#": y += 1 continue break from pprint import pprint #pprint(maze) f= True for i in range(h): if maze[i].count("#") != 0: f = False print("Impossible" if not f else "Possible")
s211329723
p03937
u683134447
1580084275
Python
Python (3.4.3)
py
Runtime Error
24
3064
547
h,w = map(int,input().split()) al = [] for _ in range(h): a = list(input()) al.append(a) i,j = 0,0 while True: al[i][j] = "." if j + 1 < w and al[i][j+1] == "#": al[i][j+1] = "." j += 1 elif i + 1 < h and al[i+1][j] == "#": al[i+1][j] = "." i += 1 else: print("Impossible") exit() if j == w-1 and i == h-1: break for i in range(h): for j in range(h): if al[i][j] == '#': print("Impossible") exit() print("Possible")
s195981583
p03937
u861141787
1580049364
Python
Python (3.4.3)
py
Runtime Error
17
3064
629
h, w = map(int, input().split()) a = [list(input()) for _ in range(h)] dy = [0, 1] dx = [1, 0] stack = [[0 for _ in range(w)] for _ in range(h)] def dfs(y, x): stack[y][x] = 1 if x == w-1 and y == h-1: return for i in range(2): ny = y + dy[i] nx = x + dx[i] if ny < 0 or ny >= h or nx < 0 or nx >= w: continue if a[ny][nx] == "#": dfs(ny, nx) break return dfs(0, 0) for i in range(h): for j in range(w): if a[i][j] == "#" and stack[i][j] == 0: print('Impossible') exit() print('Possible')
s022676457
p03937
u445624660
1577939659
Python
Python (3.4.3)
py
Runtime Error
17
3064
1081
# 右と下の両方に#があったら終了だしどちらにもなくても終了 # なんやこのクソみたいな実装は h, w = map(int, input().split()) table = [] for _ in range(h): table.append(input()) flag = False pos = [0, 0] while True: if pos == [h - 1, w - 1]: flag = True break if h <= pos[0] or w <= pos[1]: break if ( pos[0] < h - 1 and pos[1] < w - 1 and table[pos[0] + 1][pos[1]] == "#" and table[pos[0]][pos[1] + 1] == "#" ): break if pos[0] < h - 1 and pos[1] < w - 1 and table[pos[0] + 1][pos[1]] == "#": pos[0] += 1 continue elif pos[0] < h - 1 and pos[1] < w - 1 and table[pos[0]][pos[1] + 1] == "#": pos[1] += 1 continue if pos[0] == h - 1 and pos[1] < w - 1 and table[pos[0]][pos[1] + 1] == "#": pos[1] += 1 continue elif pos[0] < h - 1 and pos[1] == w - 1 and table[pos[0] + 1][pos[0]] == "#": pos[0] += 1 continue else: break print("Possible" if flag else "Impossible")
s248887202
p03937
u445624660
1577939577
Python
Python (3.4.3)
py
Runtime Error
17
3064
1032
# 右と下の両方に#があったら終了だしどちらにもなくても終了 # なんやこのクソみたいな実装は h, w = map(int, input().split()) table = [] for _ in range(h): table.append(input()) flag = False pos = [0, 0] while True: if pos == [h - 1, w - 1]: flag = True break if ( pos[0] < h - 1 and pos[1] < w - 1 and table[pos[0] + 1][pos[1]] == "#" and table[pos[0]][pos[1] + 1] == "#" ): break if pos[0] < h - 1 and pos[1] < w - 1 and table[pos[0] + 1][pos[1]] == "#": pos[0] += 1 continue elif pos[0] < h - 1 and pos[1] < w - 1 and table[pos[0]][pos[1] + 1] == "#": pos[1] += 1 continue if pos[0] == h - 1 and pos[1] < w - 1 and table[pos[0]][pos[1] + 1] == "#": pos[1] += 1 continue elif pos[0] < h - 1 and pos[1] == w - 1 and table[pos[0] + 1][pos[0]] == "#": pos[0] += 1 continue else: break print("Possible" if flag else "Impossible")
s802677333
p03937
u066455063
1577154389
Python
Python (3.4.3)
py
Runtime Error
17
2940
277
H, W = map(int, input().split()) A = [list(input()) for i in range(H)] for i in range(H): for j in range(W-1): if A[i][j] == "#": if A[i-1][j] != "#" and A[i+1][j+1] != "#": print("Impossible") exit() print("Possible")
s449554723
p03937
u905582793
1577049075
Python
Python (3.4.3)
py
Runtime Error
17
2940
446
h,w=map(int,input().split()) bd = [[.]+list(input().split())+[.] for i in range(h)] bd.insert(0,[.]*(w+1)) bd.append([.]*(w+1)) for i in range(h): for j in range(w): if bd[i][j] == "#": if i == h and j == w: print("Possible") break if bd[i+1][j] == bd[i+1][j]: print("Impossible") break if bd[i-1][j] == "#" or bd[i][j-1] == "#": print("Impossible") break bd[i][j]="."
s254341330
p03937
u617659131
1574124331
Python
Python (3.4.3)
py
Runtime Error
18
2940
365
h,w = map(int, input().split()) board = [] for i in range(h): board.append(list(input())) line = 0 column = 0 for i in range((h-1) + (w-1)): if board[line][column+1] = "#": board[line][column] = "." column += 1 elif board[line+1][column] = "#" : board[line][column] = "." line += 1 else: print("Impossible") break print("Possible")
s555229214
p03937
u933129390
1574123869
Python
Python (3.4.3)
py
Runtime Error
17
3064
568
h, w = map(int, input().split()) table = [] for i in range(h): table.append(list(input())) poss = True for i in range(h-1): for j in range(w-1): if table[i][j] == "#": if (table[i+1][j]=="#" and table[i][j+1]=="#") or (table[i+1][j]=="." and table[i][j+1]=="."): poss = False for i in range(1, h): if table[i][w-1]=="#" and table[i-1][w]=="#": poss = False for i in range(1, w): if table[h][i-1]=="#" and table[h-1][i]=="#": poss = False if poss: print("Possible") else: print("Impossible")
s443152932
p03937
u814986259
1573825242
Python
Python (3.4.3)
py
Runtime Error
17
2940
292
H,W=map(int,input().split()) prev=0 for i in range(H): s=input() id = s.index("#") if id >= prev: flag=False prev = id for j in range(prev,W): if flag ans s[j]=="#": print("Impossible") exit(0) if s[j]==".": flag=True print("Possible")
s328037854
p03937
u814986259
1573825214
Python
Python (3.4.3)
py
Runtime Error
17
2940
276
H,W=map(int,input().split()) prev=0 for i in range(H): s=input() id = s.index("#") if id >= prev: flag=False for j in range(id,W): if flag ans s[j]=="#": print("Impossible") exit(0) if s[j]==".": flag=True print("Possible")
s838836090
p03937
u223904637
1571604976
Python
PyPy3 (2.4.0)
py
Runtime Error
178
38384
442
h,w=map(int,input()) r=[] for i in range(h): r.append(list(input())) t=[] for i in range(h): for j in range(w): if r[i][j]=='#': t.append([i,j]) op=[[[0,0]]] for i in range(h+w-2): tmp=[] for j in op: tmp.append(j+[[j[-1][0]+1,j[-1][1]]]) tmp.append(j+[[j[-1][0],j[-1][1]+1]]) op=tmp for i in op: if sorted(i)==sorted(t): print('Possible') exit() print('Impossible')
s440069101
p03937
u832039789
1569796596
Python
Python (3.4.3)
py
Runtime Error
17
3060
175
n=int(input()) a=[i*30000+1 for i in range(n)] b=[30000**2-i for i in a] p=list(map(int,input().split())) for i in range(n): a[p[i]-1]+=i b[p[i]-1]+=i print(*a) print(*b)
s185224804
p03937
u832039789
1569796306
Python
Python (3.4.3)
py
Runtime Error
17
3060
169
n=int(input()) a=[i*40000 for i in range(n)] b=[40000**2-i for i in a] p=list(map(int,input().split())) for i in range(n): a[p[i]]+=i b[p[i]]+=i print(*a) print(*b)
s688260057
p03937
u296518383
1568392374
Python
Python (3.4.3)
py
Runtime Error
17
2940
1
a