結果

問題 No.3021 データベースの練習
ユーザー koyumeishikoyumeishi
提出日時 2016-09-23 22:23:29
言語 PyPy3
(7.3.13)
結果
RE  
実行時間 -
コード長 1,605 bytes
コンパイル時間 414 ms
コンパイル使用メモリ 86,960 KB
実行使用メモリ 103,024 KB
平均クエリ数 1.00
最終ジャッジ日時 2023-09-23 11:32:37
合計ジャッジ時間 6,768 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

# ジャッジコード

import sqlite3
import random
import sys

#run_type = "generator"
run_type = "judge"

argvs = sys.argv
argc  = len(argvs)
#assert(argc > 2)
print(argvs, file=sys.stderr)
n,q,w,h,seed = map(int, open(argvs[1],"r").read().split())
print(n,q,seed, file=sys.stderr)

assert((w+1)*(h+1) >= n)

random.seed( seed )

s = set()

#generate points
while len(s) < n :
  s.add( (random.randint(0,w), random.randint(0,h)) )

#initialize database
conn = sqlite3.connect(":memory:")
cur  = conn.cursor()
cur.execute("""
  CREATE TABLE point(
    id INTEGER PRIMARY KEY,
    x INTEGER,
    y INTEGER);
  """)

for p in s :
  cur.execute("""INSERT INTO point(x,y) VALUES(?,?);""", [(p[0]),(p[1])])
  print(p, file=sys.stderr)

if run_type == "judge" :
  print(q)

for i in range(q) :
  xl = random.randint(0,w)
  xh = random.randint(0,w)
  yl = random.randint(0,h)
  yh = random.randint(0,h)
  if xl > xh : 
    xl, xh = xh, xl
  if yl > yh :
    yl, yh = yh, yl

  assert(xl<=xh)
  assert(yl<=yh)

  if run_type == "judge" :
    print(xl,xh,yl,yh)
  else :
    cur.execute("""SELECT count(*) FROM point WHERE (x BETWEEN ? and ?) and  (y BETWEEN ? and ?);""", [(xl),(xh),(yl),(yh)])
    print(cur.fetchone()[0])


if run_type == "judge" :
  res = []
  sql_scripts = sys.stdin.read().split(';')
  for scr in sql_scripts :
    cur.execute(scr + ";")
    var = cur.fetchone()
    while var != None : 
      res.append(var[0])
      var = cur.fetchone()

  ans = list( map(int, open(argvs[2], "r").read().split() ) )

  print(res, file=sys.stderr)
  print(ans, file=sys.stderr)

  assert(res == ans)


0