Skip to content

Instantly share code, notes, and snippets.

@kou029w
Last active January 10, 2019 09:17
Show Gist options
  • Save kou029w/4905fd94df5032b1ecda9f867b355c6c to your computer and use it in GitHub Desktop.
Save kou029w/4905fd94df5032b1ecda9f867b355c6c to your computer and use it in GitHub Desktop.
@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

事前準備
Windows アップデートが始まったので待つ
VSCodeもアップデート
Ubuntuもアップデート

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

開始

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

長さ 4 の文字列がDDCC型文字列であるのは、文字列の 1 文字目と 2 文字目が等しく、 2 文字目と 3 文字目が異なり、 3 文字目と 4 文字目が等しいときです。

理解

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

{ grep -o . | xargs -n2 | awk '{if ($1 == $2) a[i++] = $1; print $1} END{if (a[0] && a[1] && a[0] != a[1]) print "Yes" ; else print "No"}';}

これはひどい

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

そして0点...

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

grep -o . | xargs -n2 | awk '{if ($1 == $2) a[i++] = $1} END{if (a[0] && a[1] && a[0] != a[1]) print "Yes"; else print "No"}'

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

次いこう

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

read a b c d; echo $((a*1728 + b*144 + c*12 + d))

すこしまとも

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

yatta-

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

次いこう

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

http://ddcc2017-qual.contest.atcoder.jp/tasks/ddcc2017_qual_c

bashだとめんどうそうなやつだ...パス

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

もう無理だ、しにたくなってきた

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

残り30分もあるし http://ddcc2017-qual.contest.atcoder.jp/tasks/ddcc2017_qual_c でもやるか...

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

2本収納するなよ...

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

ruby インストールしよう

sudo apt install ruby

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

  • 長さが長すぎやつは無視すればよい
  • 長さが長さなら +1
  • 長さ+1 が長さなら +1
  • 長さ+1 未満の時は後で考える

長さ+1未満の集合は、順番に a+b+1 試すか...

残った分も後で加える

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

ruby -v
ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

while str = STDIN.gets
end

これで標準入力が取得できるんだ...知らなかった

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

n, c = STDIN.gets.split(' ').map(&:to_i)

l=[]

while i = STDIN.gets
  l << i.to_i
end

l.delete_if {|i| i > c }

sum = 0
l.each {|i| sum += (i == c || i + 1 == c ? 1 : 0) }.delete_if {|i| i == c || i + 1 == c }

l.sort!
while i = l.pop
  sum+=1
  l.each do|j|
    if i + j + 1 <= c
      l-=[j]
      break
    end
  end
end

puts sum

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

1時間50分もかかった

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

間違えてた

n, c = STDIN.gets.split(' ').map(&:to_i)

l=[]

while i = STDIN.gets
  l << i.to_i
end

sum = 0
l.each {|i| sum += (i == c || i + 1 == c ? 1 : 0) }.delete_if {|i| i == c || i + 1 == c }

l.sort!
while i = l.pop
  sum+=1
  l.each_with_index do |j,ix|
    if i + j + 1 <= c
      l.delete_at(ix)
      break
    end
  end
end

puts sum

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

TLEだ

@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

整理した

n, c = STDIN.gets.split(' ').map(&:to_i)

sum = 0
l = STDIN.read.split("\n").map(&:to_i).each {|i| sum += (i == c || i + 1 == c ? 1 : 0) }.delete_if {|i| i == c || i + 1 == c }.sort

while i = l.pop
  sum+=1
  l.each_with_index do |j,ix|
    if i + j + 1 <= c
      l.delete_at(ix)
      break
    end
  end
end

puts sum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment