joke3579大佬和我尝试找到accoders代码的查重功能的实现。
你交别人的代码上去不是会有个星号然后显示原代码的id吗,然后我们尝试在采药的时候破解这个东西
然后接下来列举一些事实(以下面这份代码为例:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
namespace Fread { const int SIZE = (1 << 18); char buf[SIZE], *p1 = buf, *p2 = buf; inline char getchar() {return (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, SIZE, stdin), p1 == p2) ? EOF : *p1++);} }
namespace Fwrite { const int SIZE = (1 << 18); char buf[SIZE], *S = buf, *T = buf+SIZE; inline void flush(){ fwrite(buf, 1, S-buf, stdout), S = buf; } struct NTR{ ~NTR() { flush(); } }ztr;inline void putchar(char c){ *S++ = c; if(S == T) flush(); } }
#define getchar Fread::getchar
#define putchar Fwrite::putchar
namespace Fastio{
struct Reader{ template <typename T> Reader & operator >> (T & x) {char c = getchar(); bool f = false;while (c < '0' or c > '9') { if (c == '-') f = true;c = getchar();} x = 0;while(c >= '0' and c <= '9'){x = (x<<1)+(x<<3)+(c^48);c = getchar();} if (f) x = -x;return *this;}Reader&operator>>(char&c){ c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();return *this;}Reader&operator>>(char*str){ int len=0;char c=getchar(); while(c=='\n'||c==' '||c=='\r')c=getchar(); while(c!='\n'&&c!=' '&&c!='\r')str[len++]=c,c=getchar(); str[len]='\0'; return *this;}Reader & operator >> (float & x) {char c=getchar();short f=1,s=0;x=0;double t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader & operator >> (double & x) {char c=getchar();short f=1,s=0;x=0;double t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(long double&x){char c=getchar();short f=1,s=0;x=0;long double t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(__float128&x){char c=getchar();short f=1,s=0;x=0;__float128 t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.') c = getchar();else return x*=f, *this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return *this;}Reader(){}}cin;
struct Writer{ template <typename T> Writer & operator << (T x) {if(x == 0) return putchar('0'), *this;if(x < 0) putchar('-'), x = -x;static int sta[60], top = 0; while (x) sta[++top] = x %10, x /= 10; while (top) putchar(sta[top] + '0'), --top; return *this;} Writer&operator<<(char c){putchar(c);return*this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return *this;} typedef unsigned long long mxdouble; int precision = 6; Writer set_precision(int val) { precision = val; return *this; }template <typename T> T deal_precision(T x) {__float128 tmp = x;for(int i=0;i<=precision;i++)tmp*=10;tmp+=5;for(int i=0;i<=precision;i++) tmp/=10;return (T)tmp;}Writer&operator<<(float x){if(x<0)putchar('-'),x=-x; x=deal_precision(x); mxdouble _=x;x-=(__float128)_;static int sta[60];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;if(precision==0)return*this;putchar('.');for(int i=0;i<=precision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<precision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}Writer&operator<<(double x){if(x<0)putchar('-'),x=-x; x = deal_precision(x); mxdouble _=x;x-=(double)_;static int sta[60];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;if(precision==0)return*this;putchar('.');for(int i=0;i<precision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<precision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}Writer&operator<<(long double x){if(x<0)putchar('-'),x=-x; x = deal_precision(x); mxdouble _=x;x-=(__float128)_;static int sta[60];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;if(precision==0)return*this;putchar('.');for(int i=0;i<precision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<precision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}Writer&operator<<(__float128 x){if(x<0)putchar('-'),x=-x; x = deal_precision(x); mxdouble _=x;x-=(__float128)_;static int sta[60];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;if(precision==0)return*this;putchar('.');for(int i=0;i<precision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<precision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}Writer(){}}cout; /* 精度是后15位 nan会以“9223372036854775808.9223372036854775808”的方式输出 */
} const char * endl = "\n"; const char * space = " ";
#define cin Fastio :: cin
#define cout Fastio :: cout
#define rep(i,a,b) for ( register int (i) = (a); (i) ^ ((b)+1); ++(i) )
#define pre(i,a,b) for ( register int (i) = (a); (i) ^ ((b)-1); --(i) )
#define int long long
char str[5002];
int f[5002][5002], g[5002][5002];
signed main() {
register int T, n, l, r;
cin >> (str+1) >> T;
n = strlen(str+1);
for (register int i = 1; i <= n; i++) {
l = r = i;
while (l > 0 and r <= n and str[l] == str[r]) {
g[l][r] = 1;
l--, r++;
}
} for (register int i = 2; i <= n; i++) {
l = i-1, r = i;
while (l > 0 and r <= n and str[l] == str[r]) {
g[l][r] = 1;
l--, r++;
}
}
for (register int i = n; i >= 1; i--) {
for (register int j = 1; j <= n; j++){
f[i][j] = f[i+1][j] + f[i][j-1] - f[i+1][j-1] + g[i][j];
}
}
while (T--) {
cin >> l >> r;
cout << f[l][r] << endl;
}
}- 复制了114514份预处理/交换预处理顺序没用。
- 删掉超级快读换scanf没用。
- 改变数组名字(f改yijiuyijiubayiling,g改yiyisiwuyisi)没用。
- 改变需要用的宏定义,可行。
- 改变dp的循环嵌套顺序,可行。
- 加注释没用。
- 把预处理加入函数,没用。
- 在7的基础上把快读删了,可行。
- 随便增加一点别的操作(比如一个变量++,或者一个只有3层的空dfs)可行。
- 主函数内定义变量再操作不行。
推测:进行两次匹配,一次匹配成功则报重复。
- 将整个代码跑一个在一定范围内允许出错的字符串匹配(这个可以直接hash二分)。(不得不说,joke3579的长篇大论的快读在这里起到了用处,我只需要把这个删掉就能控制这个变量)
- 将代码编译,将汇编指令整体的操作进行匹配。这一次匹配应当比较严格,因为我只加了一个变量操作(完全没用)就可行。具体的,他应该会记录一下你系统栈里入栈和出栈的操作,然后把这些操作去重并判断两份代码是否相同(所以无论在哪里、复制相同操作多少次都会判重)。
进一步的操作:
- 发现主函数定义变量再操作没用,但是全局变量可以,于是尝试对比两份代码的汇编。发现:
全局变量是把地址引用过来操作,再引用回去。
函数内定义变量是直接新call一块地址操作,这块地址属于函数。
(方法:编译指令加个-S 编译会不过 然后把exe改txt打开)
所以函数内开大数组会爆,因为爆函数栈了。而全局变量就不会爆函数栈,因为它压根不属于函数,就是借用一下主存储器的一个内存地址。
推论:可能局部变量根本就没有被查,他查的是整个汇编指令的匹配,也就是把指令加上地址加上赋值一起检验。而主函数内的变量是隶属于主函数自己的栈的,因此没有被查。
继续操作:
- 全局变量定义顺序交换,可行。
- 主函数内操作把a++改成a+=2,可行。
证明推论正确。得解。