-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c8c3fe2
commit 81aa1df
Showing
15 changed files
with
334 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
input=gets.split.map(&:to_i) | ||
n=input[0] | ||
p1=input[1] | ||
p2=input[2] | ||
p3=input[3] | ||
t1=input[4] | ||
t2=input[5] | ||
|
||
back=-1 | ||
ans=0 | ||
n.times{|i| | ||
input=gets.split.map(&:to_i) | ||
if back==-1 then | ||
back=input[0] | ||
end | ||
ans+=(input[1]-input[0])*p1 | ||
t=input[0]-back | ||
t1.times{ | ||
if t==0 then | ||
break | ||
end | ||
t-=1 | ||
ans+=p1 | ||
} | ||
t2.times{ | ||
if t==0 then | ||
break | ||
end | ||
t-=1 | ||
ans+=p2 | ||
} | ||
ans+=t*p3 | ||
back=input[1] | ||
} | ||
puts ans |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
input=gets.split.map(&:to_i) | ||
heap=input[2] | ||
k=0 | ||
10000.times{|k| | ||
heap-=heap.gcd(input[k%2]) | ||
if heap<0 then | ||
puts 1-k%2 | ||
exit | ||
end | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
a=gets.split[0].bytes.to_a | ||
b=gets.split[0] | ||
cnt=Array.new(10,0) | ||
a.each{|i| | ||
cnt[i-48]+=1 | ||
} | ||
ans="" | ||
if cnt[0]>0 then | ||
1.upto(9){|i| | ||
if cnt[i]>0 then | ||
ans=i.to_s | ||
cnt[i]-=1 | ||
break | ||
end | ||
} | ||
end | ||
0.upto(9){|i| | ||
cnt[i].times{ | ||
ans+=i.to_s | ||
} | ||
} | ||
if ans==b then | ||
puts "OK" | ||
else | ||
puts "WRONG_ANSWER" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'set' | ||
def check(x,t) | ||
ok=false | ||
$m.each{|h| | ||
if x+t<=h[0] || h[0]+h[1]<=x then | ||
else | ||
return false | ||
end | ||
} | ||
return true | ||
end | ||
n,t=gets.split.map(&:to_i) | ||
t*=2 | ||
$m=[] | ||
n.times{|i| | ||
$m.push(gets.split.map(&:to_i)) | ||
$m[i][0]*=2 | ||
$m[i][0]-=$m[i][1] | ||
$m[i][1]*=2 | ||
} | ||
|
||
q=Set.new | ||
$m.each{|h| | ||
if(check(h[0]-t,t)) then | ||
q.add(h[0]-t) | ||
end | ||
if(check(h[0]+h[1],t)) then | ||
q.add(h[0]+h[1]) | ||
end | ||
} | ||
puts q.length |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
a=gets.split[0] | ||
now=0 | ||
ans="" | ||
while now<a.length | ||
if a[now..(now+1)]=="--" then | ||
ans+="2" | ||
now+=2 | ||
elsif a[now..(now+1)]=="-." then | ||
ans+="1" | ||
now+=2 | ||
else | ||
ans+="0" | ||
now+=1 | ||
end | ||
|
||
end | ||
puts ans |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
def check_l(x1,y1,x2,y2) | ||
if x1==x2 || y1==y2 then | ||
return false | ||
else | ||
return true | ||
end | ||
end | ||
$dx=[1,2,2,1,-1,-2,-2,-1] | ||
$dy=[2,1,-1,-2,-2,-1,1,2] | ||
def check_n(x1,y1,x2,y2) | ||
8.times{|i| | ||
if x1+$dx[i]==x2 && y1+$dy[i]==y2 then | ||
return false | ||
end | ||
} | ||
if x1==x2 && y1==y2 then | ||
return false | ||
end | ||
return true | ||
end | ||
a=gets.split[0].bytes.to_a | ||
b=gets.split[0].bytes.to_a | ||
x1=a[0]-97 | ||
y1=a[1]-49 | ||
x2=b[0]-97 | ||
y2=b[1]-49 | ||
|
||
ans=0 | ||
8.times{|x| | ||
8.times{|y| | ||
if check_l(x1,y1,x,y) then | ||
if check_n(x,y,x1,y1) then | ||
if check_n(x,y,x2,y2) then | ||
ans+=1 | ||
end | ||
end | ||
end | ||
} | ||
} | ||
puts ans |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
n=gets.to_i | ||
a=gets.split.map(&:to_i) | ||
cnt=Array.new(100005,0) | ||
a.each{|i| | ||
cnt[i]+=1 | ||
} | ||
1.upto(100003){|i| | ||
if cnt[i]<cnt[i+1] then | ||
puts "-1" | ||
exit | ||
end | ||
} | ||
puts cnt[1] | ||
a.each{|i| | ||
printf "%d ",cnt[i] | ||
cnt[i]-=1 | ||
} | ||
puts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
s=["ABSINTH", "BEER", "BRANDY", "CHAMPAGNE", "GIN", "RUM", "SAKE", "TEQUILA", "VODKA", "WHISKEY", "WINE","0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17"] | ||
n=gets.to_i | ||
ans=0 | ||
n.times{ | ||
t=gets.split[0] | ||
if s.index(t)!=nil then | ||
ans+=1 | ||
end | ||
} | ||
puts ans |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
n=gets.to_i | ||
a=gets.split.map(&:to_i) | ||
l,r=99999,0 | ||
1.upto(n){|i| | ||
if a[i-1]!=i then | ||
l=[l,i].min | ||
r=[r,i].max | ||
end | ||
} | ||
if l==99999 then | ||
puts "0 0" | ||
exit | ||
end | ||
a=((l-2>=0)?a[0..(l-2)]:[])+a[(l-1)..(r-1)].reverse+a[(r)..(a.length-1)] | ||
1.upto(n){|i| | ||
if(a[i-1]!=i) then | ||
puts "0 0" | ||
exit | ||
end | ||
} | ||
puts "#{l} #{r}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
n=gets.to_i | ||
a=gets.split.map(&:to_i).sort | ||
b,c=[],[] | ||
a.each{|k| | ||
if k%2==0 then | ||
b.push(k) | ||
else | ||
c.push(k) | ||
end | ||
} | ||
init=1 | ||
if c.length==0 then | ||
puts 0 | ||
exit | ||
end | ||
ans=0 | ||
if c.length%2==0 then | ||
for i in 1..(c.length-1) | ||
ans+=c[i] | ||
end | ||
else | ||
for i in 0..(c.length-1) | ||
ans+=c[i] | ||
end | ||
end | ||
b.each{|k| ans+=k} | ||
p ans |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
def solve(a,b) | ||
#bbabbabbabbabbabb | ||
#abababa | ||
if (a+1)*2<b || (b+1)<a then | ||
return false | ||
end | ||
return true | ||
end | ||
|
||
al,ar=gets.split.map(&:to_i) | ||
bl,br=gets.split.map(&:to_i) | ||
|
||
if solve(al,br) || solve(ar,bl) then | ||
puts "YES" | ||
else | ||
puts "NO" | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
k=gets.split[1].to_i | ||
a=gets.split.map(&:to_i) | ||
|
||
ranks=Array.new(104,0) | ||
a.each{|i| ranks[i]+=1} | ||
ans=0 | ||
n=a.length | ||
loop do | ||
if ranks[k]==n then | ||
puts ans | ||
exit | ||
end | ||
next_rank=Array.new(104,0) | ||
1.upto(k-1){|a| | ||
next_rank[a]+=[ranks[a]-1,0].max | ||
next_rank[a+1]+=[ranks[a],1].min | ||
} | ||
next_rank[k]+=ranks[k] | ||
ranks=next_rank | ||
ans+=1 | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
n,m=gets.split.map(&:to_i) | ||
comp=[] | ||
time=Array.new(n){[9999999,0]} | ||
m.times{ | ||
l,r,t,c=gets.split.map(&:to_i) | ||
for k in (l-1)..(r-1) | ||
if time[k][0]>t then | ||
time[k][0]=t | ||
time[k][1]=c | ||
end | ||
end | ||
} | ||
ans=0 | ||
n.times{|i| | ||
ans+=time[i][1] | ||
} | ||
p ans |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
m=gets.to_i | ||
k=Array.new(5){Array.new(5,0)} | ||
m.times{ | ||
input=gets.split.map(&:to_i) | ||
k[input[0]-1][input[1]-1]=1 | ||
k[input[1]-1][input[0]-1]=1 | ||
} | ||
5.times{|i| | ||
5.times{|j| | ||
5.times{|x| | ||
if i==j || j==x || x==i then | ||
next | ||
end | ||
if k[i][j]==1 && k[j][x]==1 && k[x][i]==1 then | ||
puts "WIN" | ||
exit | ||
end | ||
if k[i][j]==0 && k[j][x]==0 && k[x][i]==0 then | ||
puts "WIN" | ||
exit | ||
end | ||
} | ||
} | ||
} | ||
puts "FAIL" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
n=gets.to_i | ||
ans=0 | ||
(1<<12).times{|i| | ||
v=0 | ||
for j in 0..11 | ||
v*=10 | ||
if ((i>>j)&1)==1 then | ||
v+=1 | ||
end | ||
end | ||
if v<=n then | ||
ans+=1 | ||
end | ||
} | ||
p ans-1 | ||
|