-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
入出力解析 #8
Comments
こんにちは。急な発言、失礼します。 $ oj-template https://codeforces.com/contest/1349/problem/A
INFO:onlinejudge._implementation.logging:[x] load cookie from: /home/conao/.local/share/online-judge-tools/cookie.jar
INFO:onlinejudge._implementation.logging:[x] problem recognized: CodeforcesProblem.from_url('https://codeforces.com/contest/1349/problem/A'): https://codeforces.com/contest/1349/problem/A
INFO:onlinejudge._implementation.logging:[x] GET: https://codeforces.com/contest/1349/problem/A
INFO:onlinejudge._implementation.logging:[x] 200 OK
INFO:onlinejudge._implementation.logging:[x] save cookie to: /home/conao/.local/share/online-judge-tools/cookie.jar
ERROR:onlinejudge_template.analyzer.combined:input analyzer failed:
ERROR:onlinejudge_template.analyzer.combined:output analyzer failed:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;
int64_t solve(int vch, const vector<int64_t> & txg) {
// TODO: edit here
}
// generated by online-judge-template-generator v4.1.0 (https://github.com/kmyk/online-judge-template-generator)
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
constexpr char endl = '\n';
int vch;
cin >> vch;
vector<int64_t> txg(vch);
REP (i, vch) {
cin >> txg[i];
}
auto ans = solve(vch, txg);
cout << ans << endl;
return 0;
} |
いまのところ制御する方法はありません。 単にまじめな実装が後回しになっているだけなので、誰かが実装してくれれば解決します。もしよければプルリクエストをください。
template-generator/onlinejudge_template/analyzer/simple_patterns.py Lines 290 to 306 in acd1b45
なぜ現在こうなっているかフォーマット情報が直接には得られない場合は、サンプルケースからフォーマット情報を復元しています。復元のアルゴリズムはいくつか考えられます (現在のもの: simple_patterns.py) が、何を選択したとしても変数名の復元は原理的に不可能です。 |
- stop using random strings - start using proper implementation see #8 (comment)
scope が曖昧な issue なので混乱を防ぐため閉じておく |
この issue の主目的: 解析器の設計や解析結果のフォーマットについての正解を探す
設計方針について
入出力フォーマット解析について。
まず
<pre>N a_1 ... a_N</pre>
みたいなやつが与えられていることを仮定する場合 (主に AtCoder) は、基本的にコンパイラに寄せていくのがよいと考えています。(2.) と (3.) を lex と yacc でやることなどの利点は、処理内容をコードに埋め込むのでなく、BNF などの形で明確に定義できることです。この戦略は結果の解釈性が高く保守性に優れるのでうれしい。ただし失敗時のフォールバックとして完全 ad-hoc 解析器を用意する可能性はある。
(4.) の意味解析はつまり変数の型の決定をする。別枠で持ってきたサンプルと突合するなど。
(5.) はできるだけ計算能力の高い template engine を採用するのが望ましい。本体にプルリクを出さなくても好きな言語に対応できるようにしたいため。
<pre>N a_1 ... a_N</pre>
みたいなやつが与えられていることを仮定しない場合 (主に Codeforces + AtCoder の出力フォーマット) は難しい。選択肢はいくつか。その他の部分 (制約、グラフ判定、MOD、YES/NO、リアクティブ判定) は自然言語解析するしかなさそう。
解析結果のフォーマットについて
解析結果として得られる情報は以下になります:
議論が必要なのは「どのような変数が存在するか」「変数はどのような順で入力/出力されるか」部分の中間形式でしょう。
論点はいくつか。
TwoDimensionalPattern("a", "h", "w")
みたいなのを並べる)REP(y, "h", REP(x, "w", input("a[y][x]")))
のような感じに)a_1 a_3 ... a_{2n-1}
という指定がされていたときどうするか)a_0 a_1 ... a_{n-1}
に正規化しないa_0 a_1 ... a_{n-1}
に正規化する (+ 元の情報をどこかに残す / 残さない)現状は「変数の宣言の情報と入力順の情報は分離」「入力は構造的に」「できるだけ正規化する」「改行は保ち、空白は忘れる」がよいかなと思っています。具体的には JSON で以下のようなものを考えています。
他にも微妙なとこあるけどひとまずは置いておく。
コマンドラインインターフェースの設計について
入出力解析+コード生成はそれ単体で完結したひとまとまりの機能なので、独立したコマンドを与えておくべきだろう。
これはできるだけ設定ファイルに依存せず、template file ひとつで完結するようにするのがよさそう。
理由はふたつです。
たぶん具体的には以下のようになります。
$ oj-template [-f path/to/template.file] URL > output.file
@kyuridenamida 設計方針とフォーマットとそれぞれ意見ください
私も一度は PoC レベルのものは書いたのでやばい見落としはないはずだけど、実際に保守をした経験がないと分からないような落とし穴はあるはずなので
The text was updated successfully, but these errors were encountered: