Skip to content

Instantly share code, notes, and snippets.

@naoyat
naoyat / 040.cc
Created May 31, 2021 23:01
040 - Get More Money(★7)- (非想定解)あるノードが使われるときにそれ以前で満たしているべき条件を100bitのフラグにして、後ろからメモ化再帰 (naoya_t)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128_t LL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
#define rep(var,n) for(int var=0;var<(n);++var)
#define found(s,e) ((s).find(e)!=(s).end())
@naoyat
naoyat / 047.cc
Created May 31, 2021 22:52
047 - Monochromatic Diagonal(★7)- Z-algorithm (ACL) を用いた解法。(naoya_t)
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
typedef vector<int> vi;
#define pb push_back
#define rep(var,n) for(int var=0;var<(n);++var)
#define ALL(c) (c).begin(),(c).end()
int mp[256];
@naoyat
naoyat / 053.cc
Last active May 31, 2021 22:52
053 - Discrete Dowsing(★7)- 黄金分割探索を用いた想定解 (naoya_t) + 自作ジャッジサーバスクリプト https://gist.github.com/naoyat/d4a0778fd6aa543d23e0138582208db9
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
#define rep(var,n) for(int var=0;var<(n);++var)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
double phi = (1.0 + sqrt(5)) * 0.5, w = 1.0 / (1.0 + phi);
inline double calc_u(int d) { return round(d * w); }
@naoyat
naoyat / 049.cc
Last active June 2, 2021 03:12
049 - Flip Digits 2(★6)- xor基底を利用した非想定解。1が連続した1区間であることを利用すると掃き出しの計算量が激減する (naoya_t)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define rep(var,n) for(int var=0;var<(n);++var)
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
ll solve(int N, int M, vi& c, vi& l, vi& r) {
using P = tuple<int, int, int>;
PQ(P) pq;
@naoyat
naoyat / 053_judge.py
Last active May 29, 2021 04:40
典型#053用インタラクティブジャッジツール
#!/usr/bin/env python
#
# Problem 053 judge tool, by naoya_t
#
# eg.)
# python 053_judge.py ./a.out -- test random 50 cases, with qmax=15 (小課題4; default)
# python 053_judge.py -q 2 ./a.out -- test random 50 cases, with qmax=40 (小課題2)
# python 053_judge.py -n 1500 -k 1 -q 3 ./a.out -- test a particular case, with qmax=22 (小課題3)
# python 053_judge.py -a -q 4 ./a.out -- test all cases, with qmax=15 (小課題4)
#
@naoyat
naoyat / add_executable_files_to_gitignore.py
Last active December 26, 2018 03:49
Gitで実行可能バイナリファイルを排除する(すべての実行可能ファイルの名前を.gitignoreファイルに追加するスクリプトを書いた話) ref: https://qiita.com/naoya_t/items/159dc9a91eb0b27441c8
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
#
# add executable files to .gitignore in each directory (create if not exists)
#
from __future__ import print_function
import os
import re
import click
import six
@naoyat
naoyat / checker.py
Created August 1, 2018 06:28
atcoder checker - サンプルケースはディレクトリ [abcdef] に、ソースコードは [abcdef][0-9].cc に
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import sys
import os
import re
import time
import tempfile
import click
@naoyat
naoyat / result1.txt
Last active February 22, 2018 14:05
DL4US:Lesson4のHomeworkの出力(BLEUスコアで21%ぐらいのやつ)2セッション分。ちょっとずつ違う。
0) you may extend your stay in tokyo . </s>
生成文: 東京 に 滞在 し て も い い で す よ 。
正解文: 東京 滞在 を 延ば し て も い い で す よ 。
1) i study at school . </s>
生成文: 私 は 学校 で 勉強 し ま す 。
正解文: 私 は 学校 で 勉強 する 。
2) i always brush my coat when i come home . </s>
生成文: いつ 帰 っ て い たら いつ も コート を し ま す 。
正解文: 私 は 帰宅 する と いつ も コート に ブラシ を かけ る 。
3) your mother has made you what you are . </s>
@naoyat
naoyat / stopwatch.py
Last active April 4, 2017 04:40
stopwatch - 時間計測用ツール
# -*- encoding: utf-8 -*-
"""
stopwatch.py
by naoya_t
```
from stopwatch import stopwatch
import time
@naoyat
naoyat / csv_iterator.py
Created March 2, 2016 17:09
Iterating CSV file with auto-field-type-conversion (requires field_converter.py) and click.progressbar...
import sys
import csv
import click
from field_converter import FieldConverter
class CSV_Iterator:
def __init__(self, path, skip_header=False, with_progress_bar=False,
field_converter=None):
self.path = path
self.with_progress_bar = with_progress_bar