Skip to content

Commit

Permalink
5.18
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcxzyw committed May 18, 2019
1 parent 937859b commit 464b053
Show file tree
Hide file tree
Showing 20 changed files with 425 additions and 61 deletions.
85 changes: 85 additions & 0 deletions Checker/Adapters/UOJJudger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include "../Judger.hpp"
#include "../Network.hpp"
#include "../OJAPI.hpp"
#include "../OJAdapter.hpp"
#include "../Scanner.hpp"
#include "../Timer.hpp"
#include <iostream>
static FT readImpl(const std::string& str,
const std::string& bak) {
{
std::regex pattern("texttt\\{([.0-9]+)" + bak +
"\\}",
regexFlag4Search);
std::smatch match;
std::regex_search(str, match, pattern);
if(match.size() == 2)
return scan<FT>(match[1].str());
}
{
std::regex pattern("([.0-9]+)\\\\texttt\\{" +
bak + "\\}",
regexFlag4Search);
std::smatch match;
std::regex_search(str, match, pattern);
if(match.size() == 2)
return scan<FT>(match[1].str());
}
return 0;
}
static bool readOpt(Option& opt,
const std::string& str) {
std::string title;
{
std::regex pattern("<h1 class=\"page-header "
"text-center\">([ "
"\\S]+)</h1>",
regexFlag4Search);
std::smatch match;
std::regex_search(str, match, pattern);
if(match.size() == 2)
title = "UOJ" + match[1].str();
else
return false;
}
FT maxTime = readImpl(str, "s");
int64_t maxMem = readImpl(str, "MB");
if(maxTime == 0 || maxMem == 0)
return false;
std::cout << "\033[34m";
std::cout << "Title:UOJ" << title << std::endl;
std::cout << "Time Limit:" << maxTime << " s"
<< std::endl;
std::cout << "Memory Limit:" << maxMem << " MB"
<< std::endl;
std::cout << "Compare Mode:Text";
std::cout << "\033[0m" << std::endl;
opt.insert("TimeMode", TimeMode::perTask);
opt.insert("TimeLimit", static_cast<int64_t>(
maxTime * 1000000));
opt.insert("MemoryLimit", maxMem << 10);
opt.insert("CompareMode", CompareMode::Text);
opt.insert("TimeSamples",
fs::path("CheckerDir/UOJ-Samples"));
return true;
}
static bool runUOJ(const fs::path& exec) {
line("Loading Problem Info");
std::string execName =
exec.stem().string().substr(3);
int id = scan<int>(execName);
Option opt;
opt.insert("Exec", exec);
std::string problem;
if(!loadProblemInfo("UOJ", id, problem))
return false;
if(!readOpt(opt, problem))
return false;
auto data = scanData();
runAll(opt, data);
return true;
}
static OJAdapterInfo
reg("UOJ-Judger", std::regex("(UOJ|uoj)[0-9]+\\S*",
regexFlag4Match),
runUOJ);
11 changes: 8 additions & 3 deletions Checker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ find_program(HAS_PERF perf)
find_program(HAS_SYZOJTOOLS syzoj)

set (CHECKER_VERSION_MAJOR 2)
set (CHECKER_VERSION_MINOR 8)
set (CHECKER_VERSION_PATCH 4)
set (CHECKER_VERSION_MINOR 9)
set (CHECKER_VERSION_PATCH 0)

option(BZOJ_JUDGER "bzoj-judger" ON)
option(LOJ_JUDGER "loj-judger" ON)
option(UOJ_JUDGER "uoj-judger" ON)

if(HAS_SYZOJTOOLS)
option(USE_SYZOJTOOLS "syzoj-tools for LibreOJ" OFF)
Expand Down Expand Up @@ -62,8 +63,12 @@ if(LOJ_JUDGER)
set (JudgerSrc ${JudgerSrc} Adapters/LOJJudger.cpp)
endif(LOJ_JUDGER)

if(UOJ_JUDGER)
set (JudgerSrc ${JudgerSrc} Adapters/UOJJudger.cpp)
endif(UOJ_JUDGER)

set (SharedSrc Checker.cpp Common.cpp Judger.cpp OJAdapter.cpp OJAPI.cpp
RunnerShared.cpp Scanner.cpp Timer.cpp)
RunnerShared.cpp Scanner.cpp Timer.cpp Network.cpp)

link_libraries(stdc++fs)
add_executable(Checker ${SharedSrc} ${JudgerSrc} ${PlatformSrc})
19 changes: 3 additions & 16 deletions Checker/Common.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Common.hpp"
#include "Network.hpp"
#include "Platforms/Platform.hpp"
#include <algorithm>
#include <chrono>
Expand Down Expand Up @@ -115,22 +116,8 @@ fs::path downloadFile(const std::string& url,
!verifyZip(cacheFile))
fs::remove(cacheFile);
if(!fs::exists(cacheFile)) {
std::cout << "Downloading file " << url
<< std::endl;
line("wget");
std::string cmd =
"wget --dns-timeout=20 "
"--connect-timeout=20 "
"--read-timeout=600 "
"--tries=5 "
"--https-only -v "
"--no-use-server-"
"timestamps -O CheckerDir/Cache/" +
pid + " " + url;
std::cout << cmd << std::endl;
int res = system(cmd.c_str());
line("");
if(res != 0 ||
bool res = download(url, cacheFile);
if(!res ||
(verify && !verifyZip(cacheFile))) {
if(fs::exists(cacheFile))
fs::remove(cacheFile);
Expand Down
7 changes: 4 additions & 3 deletions Checker/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <iostream>
#include <map>
#include <regex>
#include <sstream>
#include <string>
using std::int64_t;
using SourceLocation =
Expand Down Expand Up @@ -69,9 +70,9 @@ fs::path downloadFile(const std::string& url,
bool unzip(const fs::path& path);
template <typename T>
inline T scan(const std::string& str) {
T res = {};
std::from_chars(str.c_str(),
str.c_str() + str.size(), res);
std::stringstream ss(str);
T res{};
ss >> res;
return res;
}
constexpr auto regexFlag4Search =
Expand Down
18 changes: 18 additions & 0 deletions Checker/Network.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "Network.hpp"
bool download(const std::string& url,
const fs::path& dst) {
std::cout << "Downloading file " << url
<< std::endl;
line("wget");
std::string cmd = "wget --dns-timeout=20 "
"--connect-timeout=20 "
"--read-timeout=600 "
"--tries=5 -v "
"--no-use-server-"
"timestamps -O " +
dst.string() + " " + url;
std::cout << cmd << std::endl;
int res = system(cmd.c_str());
line("");
return res == 0;
}
6 changes: 6 additions & 0 deletions Checker/Network.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once
#include "Common.hpp"
bool access(const std::string& url,
const std::string& name);
bool download(const std::string& url,
const fs::path& dst);
7 changes: 5 additions & 2 deletions Checker/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ AC后询问OJ上的时间并加入samples中,在BZOJ计时方式下skip掉剩
2.8.4(5.14)
修复系统时间超时产生SIGXCPU信号,误判TLE的问题。

2.9.0(5.15)
支持UOJ题目读取与样例数据下载

## TODO List

- [x] 跨Windows平台、分离平台实现
Expand All @@ -136,8 +139,8 @@ AC后询问OJ上的时间并加入samples中,在BZOJ计时方式下skip掉剩
- [x] 自动下载并解压数据,自动获取时限和内存限制
- [ ] 全部AC时自动提交代码
- [x] 自动更新(使用CMake)
- [ ] 本地性能比较(从LOJ上扒代码
- [ ] 序列化配置OJ
- [ ] 本地性能比较(从OJ上扒代码
- [x] 序列化配置OJ
- [ ] 功能模块化
- [x] 评测机与本机时间缩放
- [ ] 支持文件输入输出
Expand Down
4 changes: 3 additions & 1 deletion OI-Source.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@
"string": "cpp",
"any": "cpp",
"source_location": "cpp",
"*.idl": "cpp"
"*.idl": "cpp",
"hash_map": "cpp",
"hash_set": "cpp"
},
"latex-workshop.intellisense.citation.maxfilesizeMB": 128,
"latex-workshop.latex.recipes": [
Expand Down
4 changes: 2 additions & 2 deletions Queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,10 @@
- [ ] UOJ450
- [ ] LOJ6072
- [x] bzoj2111
- [ ] bzoj3501
- [x] bzoj3501
- [ ] LOJ#6608. 无意识的石子堆
- [ ] LOJ#562. 「LibreOJ Round #9」Tangjz 的背包
- [ ] LOJ#6358. 前夕
- [x] LOJ#6358. 前夕
# 扩展欧几里得
- [ ] LOJ#6440
- [ ] CF868G
Expand Down
60 changes: 60 additions & 0 deletions Review/Combinatorics/Bell.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
\section{贝尔数}
贝尔数$B_n$是大小为$n$的集合的划分方案数。

贝尔数的前几项为:$1, 1, 2, 5, 15, 52, 203, 877,\cdots$(参见OEIS-A000110\\
\url{https://oeis.org/A000110})

$B_n$满足等式:
\begin{eqnarray*}
B_0=B_1&=&1\\
B_{n+1}&=&\sum_{i=0}^n{\binomial{n}{i}B_i}\\
B_n&=&\sum_{i=1}^n{\stirlingB{n}{i}}
\end{eqnarray*}

\subsection{因子分解应用}
若无平方因子的整数$\displaystyle n=\sum_{i=1}^k{p_i}$
则整数$n$可以分解为$B_k$种因子的乘积表达式。
\subsection{贝尔数计算}
\subsubsection{DFS}若要得到不同方案的状态表示,限制下阶段DFS的集合大小以避免重复计算。
\subsubsection{贝尔三角形}
与推杨辉三角形类似,递推方法如下:
\begin{eqnarray*}
A[0][1]&=&1\\
A[n][1]&=&A[n-1][n]\\
A[n][m]&=&A[n][m-1]+A[n-1][m-1]\\
B_n&=&A[n][1]
\end{eqnarray*}
使用滚动数组优化空间。

\index{*TODO!贝尔三角形的意义}
\subsubsection{生成函数法}
利用Bell数的生成函数$e^{e^x-1}$,计算多项式exp。
\subsubsection{贝尔数模质数}
\index{T!Touchard's Congruence}
\begin{theorem}{Touchard's Congruence}
\begin{eqnarray*}
B_{p+n}&\equiv& B_n+B_{n+1}\pmod{p}\\
B_{p^m+n}&\equiv& mB_n+B_{n+1}\pmod{p}\\
\end{eqnarray*}
\end{theorem}

首先$O(p^2)$使用贝尔三角形预处理出$p$以内的贝尔数模$p$的值。

若要求$B_n$,则对$n$进行$p$进制分解,记$n_i$$n$在权为$p^i$时的位。

以最低位作为下标,从$B_{0\ldots p}$开始递推,逐步加$p^i$递推直至次数等于$n_i$
最后取数组第$n_0$项。

参考代码(PA2008 Cliquers Strike Back):
\lstinputlisting{Source/Source/Count/bzoj3501.cpp}

时间复杂度$O(p^2lg_pn)$

该内容参考了Claris的博客\footnote{
BZOJ3501 : PA2008 Cliquers Strike Back
\url{https://www.cnblogs.com/clrs97/p/4714467.html}
}和Wikipedia-EN\footnote{
Bell number - Wikipedia:Modular arithmetic\\
\url{https://en.wikipedia.org/wiki/Bell\_number\#Modular\_arithmetic}
}。
{\bfseries 令人失望的是维基百科已全面被封。}
1 change: 1 addition & 0 deletions Review/Combinatorics/Combinatorics.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ \chapter{组合数学}
\input{Combinatorics/BoxAndBall}
\input{Combinatorics/Catalan}
\input{Combinatorics/Stirling}
\input{Combinatorics/Bell}
\input{Combinatorics/Lucas}
\input{Combinatorics/Permutation}
\section{其它公式与定理}
Expand Down
2 changes: 1 addition & 1 deletion Review/GameTheory/SGFunction.tex
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ \subsection{SG定理}
\index{S!SpragueGrundy Theorem}

\begin{theorem}[SpragueGrundy Theorem A]
\bfseries 假设当某玩家无法操作时,该玩家失败。\mdseries
当某玩家无法操作时,认为该玩家失败。
$SG(x)=0$,则该状态为必败态,否则为必胜态。
\end{theorem}

Expand Down
31 changes: 0 additions & 31 deletions Review/Math/GeneratingFunction.tex
Original file line number Diff line number Diff line change
Expand Up @@ -56,37 +56,6 @@ \subsection{指数型生成函数}
\hline
\end{tabular}

\subsection{贝尔数}
贝尔数$B_n$是大小为$n$的集合的划分方案数。

贝尔数的前几项为:$1, 1, 2, 5, 15, 52, 203, 877,\cdots$(参见OEIS-A000110\\
\url{https://oeis.org/A000110})

$B_n$满足等式:
\begin{eqnarray*}
B_0=B_1&=&1\\
B_{n+1}&=&\sum_{i=0}^n{\binomial{n}{i}B_i}\\
B_n&=&\sum_{i=1}^n{\stirlingA{n}{i}}
\end{eqnarray*}

\subsubsection{因子分解应用}
若无平方因子的整数$\displaystyle n=\sum_{i=1}^k{p_i}$
则整数$n$可以分解为$B_k$种因子的乘积表达式。
\subsubsection{贝尔数计算}
\paragraph{DFS}若要得到不同方案的状态表示,限制下阶段DFS的集合大小以避免重复计算。
\paragraph{贝尔三角形}
与推杨辉三角形类似,递推方法如下:
\begin{eqnarray*}
A[0][1]&=&1\\
A[n][1]&=&A[n-1][n]\\
A[n][m]&=&A[n][m-1]+A[n-1][m-1]\\
B_n&=&A[n][0]
\end{eqnarray*}
使用滚动数组优化空间。

\index{*TODO!贝尔三角形的意义}
\paragraph{生成函数法}
利用Bell数的生成函数$e^{e^x-1}$,计算多项式exp。
\subsection{自然数幂求和}

$B_n$为第$i$个伯努利数,其中$B_0=1$
Expand Down
3 changes: 2 additions & 1 deletion Review/NetworkFlows/Tricks.tex
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ \subsection{费用流}
1作为该边边权。
\item 若已知走一条边之前必定已经走完了另外几条边,则考虑动态加边。
\item 对于层数较少,结构简单的图,考虑使用其它数据结构贪心模拟费用流。
{\bfseries 注意还要模拟退流(即反悔)。}
\item (待验证)判断一条边是否一定被选:在残量网络上跑SPFA,若距离差不等于边权则必选。
\item 餐巾计划问题:一条脏餐巾被传递多次只能代表1的流量,会误导MCMF。考虑修改建图方式:
一条餐巾被使用一次必须要直接从S流到T,脏餐巾只能从S重新流出,由于每天会使用r条餐巾,再从
Expand All @@ -36,7 +37,7 @@ \subsection{费用流}
费用为0,另一条为$-p_iu_i$。只使用一个精灵球时,MCMF将贪心选择费用为0的边。
简单地说,用流量和费用+贪心性质诱导MCMF。
\item SNOI2019通信:$O(n^2)$连边过多,可以考虑分治连边,按照点值添加新点,然后让差值在
新点连起来的链上累积,边数$O(n\lg n)$
新点连起来的链上累积,边数$O(n\lg n)$关键字:可累加的代价(距离绝对值)
\end{itemize}

上述内容参考了胡伯涛的2007年国家集训队论文《最小割模型在信息学竞赛中的应用》
Expand Down
5 changes: 5 additions & 0 deletions Review/NumberTheory/Euler.tex
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ \subsection{线性推逆元}
以上内容参考了Miskcoo的博客\footnote{[数论]线性求所有逆元的方法 – Miskcoo's Space\\
\url{http://blog.miskcoo.com/2014/09/linear-find-all-invert}}

{\bfseries
Warning:试验发现这种方法会造成75\%左右的Cache Miss,严重影响性能,推荐使用下面的方法,
尤其是预处理阶乘逆元时。
}

Update:还有更一般的做法,可以在$O(n+\lg p)$内推出任意$n$个非0数的逆元:

首先计算出前$i$个数的前缀积$M_i$,然后快速幂计算$M_n^{-1}$,最后从后往前倒推计算每个数的
Expand Down
1 change: 1 addition & 0 deletions Review/Other/TricksAndIdeas.tex
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ \subsection{注意事项/常见转化/思想}
\sum{(x_i-\bar{x})^2}=\sum{x_i^2}-n\bar{x}^2
\end{displaymath}
\item 考虑将一些依赖/包含关系描述为图/树/DAG的形式。
\item 当计数出现重复时,考虑设出容斥系数函数$f(x)$,然后利用等式解出。
\end{itemize}
\subsection{比赛注意事项}
\subsubsection{Linux/GCC工具}
Expand Down
2 changes: 1 addition & 1 deletion Review/Recommendation.tex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ \section{个人博客}
\item fjzzq2002 \url{https://www.cnblogs.com/zzqsblog}
\item FlashHu \url{http://www.cnblogs.com/flashhu/}
\item Claris \url{https://www.cnblogs.com/clrs97/}
\item negiizhao \url{http://negiizhao.blog.uoj.ac/}
\item negiizhao \url{http://negiizhao.blog.uoj.ac/} 毒瘤
\end{itemize}
\section{好用的网站/工具}
\begin{itemize}
Expand Down
Loading

0 comments on commit 464b053

Please sign in to comment.