Last active
March 11, 2017 03:56
-
-
Save cielavenir/6cc08748626311b8671d959a265215ac to your computer and use it in GitHub Desktop.
AtCoder 入稿スクリプト
This file contains hidden or 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
| #!/usr/bin/ruby | |
| require 'mechanize' | |
| ATCODER_USER='' | |
| ATCODER_PASSWORD='' | |
| =begin | |
| 入力は | |
| --- | |
| コンテスト名 | |
| >タスクID | |
| name:問題名 | |
| time:制限時間(ms) | |
| memory:メモリ制限(KB) | |
| 問題文 | |
| --- | |
| のような形式。DATA部を参考にして下さい | |
| =end | |
| def getarchive(f) | |
| contest=f.gets.chomp | |
| arc=[] | |
| data={} | |
| statement=nil | |
| line=f.gets | |
| line.chomp! | |
| id=line[1..-1] | |
| while line=f.gets | |
| if line.chomp.empty? | |
| statement='' | |
| elsif line[0,1]=='>' | |
| data[:id]=id | |
| data[:statement]=statement | |
| arc<<data | |
| data={} | |
| id=line.chomp[1..-1] | |
| statement=nil | |
| else | |
| if statement | |
| statement<<line | |
| else | |
| x,y=line.chomp.split(':',2) | |
| data[x.to_sym]=y | |
| end | |
| end | |
| end | |
| data[:id]=id | |
| data[:statement]=statement | |
| arc<<data | |
| [contest,arc] | |
| end | |
| CONTEST,ARC=getarchive STDIN # DATA | |
| BASE="https://#{CONTEST}.contest.atcoder.jp" | |
| def login(agent) | |
| agent.get('https://practice.contest.atcoder.jp/login') | |
| form=agent.page.form | |
| form['name']=ATCODER_USER | |
| form['password']=ATCODER_PASSWORD | |
| form.submit | |
| end | |
| agent=Mechanize.new | |
| login(agent) | |
| agent.get(BASE+'/assignments') | |
| links=agent.page.links.select{|e|e.href&&e.href.start_with?('/tasks/update')} | |
| raise if links.size!=ARC.size | |
| links.zip(ARC){|link,data| | |
| agent.get(BASE+link.href) | |
| form=agent.page.form | |
| #mandatory | |
| #form['task_screen_name']=data[:id] | |
| form['task_name']=data[:name] | |
| form['memory_limit']=data[:memory] | |
| form['stack_limit']=data[:memory] | |
| form['time_limit']=data[:time] | |
| form['statement']=data[:statement] | |
| #not mandatory | |
| form['copyright']=data[:copyright].to_s | |
| form['source_name']=data[:source].to_s | |
| form['source_url']=data[:source_url].to_s | |
| form.submit | |
| } | |
| __END__ | |
| joi2007ho | |
| >joi2007ho1 | |
| name:最大の和 | |
| time:1000 | |
| memory:64000 | |
| <p><a href="https://www.ioi-jp.org/joi/2006/2007-ho-prob_and_sol/2007-ho.pdf">PDFリンク</a></p> | |
| >joi2007ho2 | |
| name:最長の階段 | |
| time:1000 | |
| memory:64000 | |
| <p><a href="https://www.ioi-jp.org/joi/2006/2007-ho-prob_and_sol/2007-ho.pdf">PDFリンク</a></p> | |
| >joi2007ho3 | |
| name:最古の遺跡 | |
| time:3000 | |
| memory:64000 | |
| <p><a href="https://www.ioi-jp.org/joi/2006/2007-ho-prob_and_sol/2007-ho.pdf">PDFリンク</a></p> | |
| >joi2007ho4 | |
| name:最悪の記者 | |
| time:2000 | |
| memory:64000 | |
| <p><a href="https://www.ioi-jp.org/joi/2006/2007-ho-prob_and_sol/2007-ho.pdf">PDFリンク</a></p> | |
| >joi2007ho5 | |
| name:最軽量のモビール | |
| time:1000 | |
| memory:64000 | |
| <p><a href="https://www.ioi-jp.org/joi/2006/2007-ho-prob_and_sol/2007-ho.pdf">PDFリンク</a></p> |
This file contains hidden or 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
| #!/usr/bin/env ruby | |
| =begin | |
| 入力は8行 | |
| --- | |
| 2007 | |
| 最大の和 | |
| 最長の階段 | |
| 最古の遺跡 | |
| 最悪の記者 | |
| 最軽量のモビール | |
| 実行時間制限 1 秒 1 秒 3 秒 2 秒 1 秒 | |
| メモリ制限 64MB 64MB 64MB 64MB 64MB | |
| --- | |
| のような形式。基本、joi_parse.rbから得る。 | |
| atcoder_form.rbにパイプ。 | |
| =end | |
| T={ | |
| '2006'=>'https://www.ioi-jp.org/joi/2005/2006-ho-prob_and_sol/2006-ho.pdf', | |
| '2007'=>'https://www.ioi-jp.org/joi/2006/2007-ho-prob_and_sol/2007-ho.pdf', | |
| '2008'=>'https://www.ioi-jp.org/joi/2007/2008-ho-prob_and_sol/2008-ho.pdf', | |
| '2009'=>'https://www.ioi-jp.org/joi/2008/2009-ho-prob_and_sol/2009-ho.pdf', | |
| '2010'=>'https://www.ioi-jp.org/joi/2009/2010-ho-prob_and_sol/2010-ho.pdf', | |
| '2011'=>'https://www.ioi-jp.org/joi/2010/2011-ho-tasks_data/2011-ho.pdf', | |
| '2012'=>'https://www.ioi-jp.org/joi/2011/2012-ho-prob_and_sol/2012-ho.pdf', | |
| '2013'=>'https://www.ioi-jp.org/joi/2012/2013-ho/2013-ho.pdf', | |
| '2014'=>'https://www.ioi-jp.org/joi/2013/2014-ho/2014-ho.pdf', | |
| '2015'=>'https://www.ioi-jp.org/joi/2014/2015-ho/2015-ho.pdf', | |
| '2016'=>'https://www.ioi-jp.org/joi/2015/2016-ho/2016-ho.pdf', | |
| '2017'=>'https://www.ioi-jp.org/joi/2016/2017-ho/2017-ho.pdf', | |
| } | |
| require 'bigdecimal' | |
| year=gets.chomp | |
| contest="joi#{year}ho" | |
| names=5.times.map{gets.chomp} | |
| times=gets.scan(/[\d\.]+/).map{|e|(BigDecimal(e)*1000).to_i} | |
| memory=gets.scan(/[\d]+/).map{|e|e.to_i*1000} | |
| puts contest | |
| 5.times{|i| | |
| puts ">#{contest}#{i+1}" | |
| puts "name:#{names[i]}" | |
| puts "time:#{times[i]}" | |
| puts "memory:#{memory[i]}" | |
| puts | |
| puts "<p><a href=\"#{T[year]}\">PDFリンク</a></p>" | |
| } |
This file contains hidden or 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
| #!/usr/bin/ruby | |
| require 'poppler' | |
| doc=Poppler::Document.new(ARGV[0]) | |
| i=1 | |
| doc.each{|page| | |
| lines=page.get_text.each_line.map(&:chomp) | |
| #p lines | |
| #problem | |
| lines.each_cons(2).with_index{|(x,y),j|break if j>=5;if x==i.to_s&&!(y=~/^[-0-9 ]+$/)&&y.size<60 then puts y;i+=1;break end} | |
| #overview | |
| #lines.each{|e|puts e if e.include?('実行時間') || e.include?('メモリ')} | |
| } | |
| #2009以前のOverviewSheetは縦書きなので、 | |
| #pdftk OverviewSheet.pdf cat 1-endeast output out.pdf | |
| #で横書きに変換する。 |
This file contains hidden or 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
| 作成順 | |
| - joi_parse.rb | |
| - def login | |
| - linksループの中身 | |
| - atcoder_joihelper.rb | |
| - def getarchive | |
| - linksループの外側 | |
| 結構他の人と比べて独特な組み方してる気がする…隠しページがベースになっているからかな… |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment