LoginSignup
1
0

More than 5 years have passed since last update.

CodeIQ 「進捗ないですマーク」問題の僕の回答

Posted at

CodeIQ 「進捗ないですマーク」問題の僕の回答です。

Python の皮をかぶった SQL です。

#sinchokuniq

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sqlite3


def main():
    try:
        conn = sqlite3.connect(':memory:')
        strSQL = '''
SELECT
        'invalid'
    WHERE
        :1 & 1 = 0
UNION ALL
SELECT
    *
FROM
    (
WITH P(x,y) AS (
        WITH X(x) AS (
                SELECT 1 WHERE :1 & 1 = 1
                UNION ALL SELECT x + 1 FROM X WHERE x < :1)
        SELECT X,1 FROM X
        UNION ALL SELECT P.x,P.y + 1 FROM P WHERE y < :1)
    SELECT
        group_concat(
            CASE
                WHEN
                        x = 1
                        or x = :1
                        or x = y
                    THEN 'n'
                ELSE '.'
            END,'')
    FROM P
    GROUP BY y
);
'''
        n = int(input())
        lines = conn.execute(strSQL, (n,)).fetchall()
        for line in lines:
            print(line[0])
    finally:
        conn.close()


if __name__ == '__main__':
    main()
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0