# 题解

$$s0 = \sum_{i=0}^{n} i ^ 0 \\ s1 = \sum_{i=0}^{n} i ^ 1 \\ s2 = \sum_{i=0}^{n} i ^ 2 \\ s3 = \sum_{i=0}^{n} i ^ 3 \\ s4 = \sum_{i=0}^{n} i ^ 4$$

$$s0 = n + 1 \\ s1 = \frac{n(n+1)}{2} \\ s2 = \frac{n(n+1)(2n+1)}{6} \\ s3 = \left (\frac{n(n+1)}{2}\right)^2$$

$$s4 = \frac{n(n+1) (2n+1)(3n^2 + 3n-1)}{30}$$

wtf这这这……解数独只有 10 分？

wtf还限制枚举顺序？

# 代码及附加文件

## 链接：problem_73

g++ -o x 1.cpp -DpAll

#pragma GCC optimize("Ofast","inline")
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof (x))
#define For(i,a,b) for (int i=a;i<=b;i++)
#define Fod(i,b,a) for (int i=b;i>=a;i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define _SEED_ ('C'+'L'+'Y'+'A'+'K'+'I'+'O'+'I')
#define outval(x) printf(#x" = %d\n",x)
#define outvec(x) printf("vec "#x" = ");for (auto _v : x)printf("%d ",_v);puts("")
#define outtag(x) puts("----------"#x"----------")
#define outarr(a,L,R) printf(#a"[%d...%d] = ",L,R);\
For(_v2,L,R)printf("%d ",a[_v2]);puts("");
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> vi;
LL x=0,f=0;
char ch=getchar();
while (!isdigit(ch))
f|=ch=='-',ch=getchar();
while (isdigit(ch))
x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return f?-x:x;
}
namespace P1{
int main(){
OPEN(1);
For(i,1,10){
cerr<<"Test "<<i<<endl;
ULL a,b,c;
cin>>a>>b>>c;
// a * b % c
ULL ans=0;
for (;b;b>>=1,a=(a+a)%c)
if (b&1)
ans=(ans+a)%c;
cout<<ans<<endl;
}
return 0;
}
}
namespace P2{
LL n,mod;
if ((x+=y)>=mod)
x-=mod;
}
void Del(LL &x,LL y){
if ((x-=y)<0)
x+=mod;
}
struct Mat{
LL v[3][3];
Mat(){}
Mat(LL _x){
clr(v);
For(i,0,2)
v[i][i]=_x;
}
friend Mat operator * (Mat a,Mat b){
Mat c(0);
For(i,0,2)
For(j,0,2)
For(k,0,2)
return c;
}
friend Mat operator ^ (Mat x,LL y){
Mat ans(1);
for (;y;y>>=1,x=x*x)
if (y&1)
ans=ans*x;
return ans;
}
}M(0),A;
int main(){
OPEN(2);
For(i,1,10){
cerr<<"Test "<<i<<endl;
M.v[0][0]=1%mod;
M.v[1][0]=2%mod;
M.v[2][0]=1%mod;
M.v[0][1]=1%mod;
M.v[1][1]=1%mod;
M.v[0][2]=1%mod;
A=Mat(0);
A.v[0][0]=1%mod;
A=A*(M^n);
LL res=(A.v[0][0]-A.v[0][1]*2+A.v[0][2])%mod;
res=(res+mod)%mod;
cout<<res<<endl;
}
return 0;
}
}
namespace P3{
unsigned long long s0,s1,s2,s3,s4,i,n;
int main(){
OPEN(3);
cin>>n;
s0=n+1;
s1=n/2*(n+1);
s2=n/2*(n+1)*(((n*2)+1)/3);
s3=n/2*(n+1),s3*=s3;
s4=n/10*(n+1)*((n*2+1)/3)*(3*n+3*n*n-1);
cout<<s0<<endl<<s0<<endl<<s1<<endl<<s1<<endl<<s2<<endl
<<s2<<endl<<s3<<endl<<s3<<endl<<s4<<endl<<s4<<endl;
return 0;
}
}
namespace P4{
const int N=5005,INF=0x3F3F3F3F;
int n,m,type;
int seed;
int Rand(){
static const int P=1e9+7,Q=83978833,R=8523467;
return seed=((LL)Q*seed%P*seed+R)%P;
}
int a[N][N];
void Input(){
For(i,1,n)
For(j,1,m)
a[i][j]=bool((Rand()%8)>0);
}
LL count1(){
LL ans=0;
For(i,1,n)
For(j,1,m)
if (a[i][j])
ans++;
return ans*(ans-1);
}
int v1[N][N],v2[N][N],v3[N][N],v4[N][N];
void ckmin(int &a,int b){
a=min(a,b);
}
LL count2(){
For(i,0,n+1)
For(j,0,n+1)
v1[i][j]=v2[i][j]=v3[i][j]=v4[i][j]=INF;
For(i,1,n)
For(j,1,n){
if (!a[i][j])
v1[i][j]=-i-j;
ckmin(v1[i][j],v1[i-1][j]);
ckmin(v1[i][j],v1[i][j-1]);
}
For(i,1,n)
Fod(j,n,1){
if (!a[i][j])
v2[i][j]=-i+j;
ckmin(v2[i][j],v2[i-1][j]);
ckmin(v2[i][j],v2[i][j+1]);
}
Fod(i,n,1)
For(j,1,n){
if (!a[i][j])
v3[i][j]=+i-j;
ckmin(v3[i][j],v3[i+1][j]);
ckmin(v3[i][j],v3[i][j-1]);
}
Fod(i,n,1)
Fod(j,n,1){
if (!a[i][j])
v4[i][j]=+i+j;
ckmin(v4[i][j],v4[i+1][j]);
ckmin(v4[i][j],v4[i][j+1]);
}
LL ans=0;
For(i,1,n)
For(j,1,n)
if (a[i][j])
ans+=min(min(v1[i][j]+i+j,v2[i][j]+i-j)
,min(v3[i][j]-i+j,v4[i][j]-i-j));
return ans;
}
int main(){
OPEN(4);
For(i,1,10){
cerr<<"Test "<<i<<endl;
Input();
cout<<(type==1?count2():count1())<<endl;
}
return 0;
}
}
namespace P5{
const int N=5005,INF=0x3F3F3F3F;
int n,m,type;
int seed;
int Rand(){
static const int P=1e9+7,Q=83978833,R=8523467;
return seed=((LL)Q*seed%P*seed+R)%P;
}
int a[N][N];
void Input(){
For(i,1,n)
For(j,1,m)
a[i][j]=bool((Rand()%8)>0);
}
int h[N][N];
int len[N],H[N],top;
LL count3(){
For(i,0,n)
For(j,0,n+1)
h[i][j]=0;
For(i,1,n)
For(j,1,n)
if (a[i][j])
h[i][j]=h[i-1][j]+1;
else
h[i][j]=0;
LL ans=0;
For(i,1,n){
len[0]=H[0]=top=0;
For(j,1,n+1){
int now=1;
while (top>0&&H[top]>=h[i][j]){
if (H[top-1]>=h[i][j]){
ans+=(LL)len[top]*(len[top]+1)/2*(H[top]-H[top-1]);
len[top-1]+=len[top];
top--;
}
else {
ans+=(LL)len[top]*(len[top]+1)/2*(H[top]-h[i][j]);
now+=len[top];
top--;
}
}
top++;
len[top]=now,H[top]=h[i][j];
}
//			cerr<<"i = "<<i<<endl;
}
return ans;
}
int main(){
OPEN(5);
For(i,1,10){
cerr<<"Test "<<i<<endl;
Input();
cout<<count3()<<endl;
}
return 0;
}
}
namespace P6{
ULL a,b,c,t,k,n;
ULL rd(ULL &t){
t=(t*t*a+b)%c;
return t;
}
int main(){
OPEN(6);
For(i,1,10){
cerr<<"Test "<<i<<endl;
cin>>n>>a>>b>>c;
k=0;
ULL t=0,t1=0;
do {
rd(t);
rd(t1);
rd(t1);
k++;
} while (k<=n&&t!=t1);
ULL k2=0;
do {
rd(t);
rd(t1);
rd(t1);
k2++;
if (t==t1)
break;
} while (k+k2<=n);
if (t==t1){
n-=k-k2;
n%=k2;
while (n--)
rd(t);
}
cout<<t<<endl;
}
return 0;
}
}
namespace P7{
const int N=18;
int n=16;
char g[N][N];
char ans[N*N];
namespace DLX{
const int N=16*16*16+5,M=16*16*4+5,S=N*4+M+N;
int n,m,cnt;
int x[S],y[S],U[S],D[S],L[S],R[S],C[M];
char now[N];
void init(int _n,int _m){
n=_n,m=_m;
cnt=m;
clr(U),clr(D),clr(L),clr(R),clr(C);
For(i,0,m)
L[i]=i-1,R[i]=i+1,D[i]=U[i]=i;
L[0]=m,R[m]=0;
}
cnt++,x[cnt]=i,y[cnt]=j;
L[cnt]=cnt-1,R[cnt]=cnt+1;
D[cnt]=j,D[U[j]]=cnt,U[cnt]=U[j],U[j]=cnt;
C[j]++;
}
void Delete(int k){
L[R[k]]=L[k],R[L[k]]=R[k];
for (int i=D[k];i!=k;i=D[i])
for (int j=R[i];j!=i;j=R[j])
U[D[j]]=U[j],D[U[j]]=D[j],C[y[j]]--;
}
void Reset(int k){
L[R[k]]=R[L[k]]=k;
for (int i=U[k];i!=k;i=U[i])
for (int j=L[i];j!=i;j=L[j])
U[D[j]]=D[U[j]]=j,C[y[j]]++;
}
int check(){
For(i,1,256)
if (now[i]=='Y')
return 1;
else if (now[i]>ans[i])
return 0;
return 1;
}
int checkord(){
For(i,1,256)
if (ans[i]!=now[i])
return now[i]<ans[i];
return 0;
}
int solve(){
/*		if (!check())
return 0;*/
if (!R[0]){
if (checkord())
For(i,1,256)
ans[i]=now[i];
return 1;
}
int k=R[0];
for (int i=R[0];i;i=R[i])
if (C[i]<C[k])
k=i;
Delete(k);
int ans=0;
for (int i=D[k];i!=k;i=D[i]){
int r=x[i];
now[(r-1)/16+1]='A'+(r-1)%16;
for (int j=R[i];j!=i;j=R[j])
Delete(y[j]);
ans|=solve();
for (int j=L[i];j!=i;j=L[j])
Reset(y[j]);
now[(r-1)/16+1]='Y';
}
Reset(k);
return ans;
}
}
int a[N][N];
int Hash(int x,int y,int z){
return x*16*16+(y-1)*16+z;
}
int solve(int po){
For(i,1,n)
scanf("%s",g[i]+1);
For(i,1,n)
For(j,1,n)
if (isupper(g[i][j]))
a[i][j]=g[i][j]-'A'+1;
else
a[i][j]=0;
DLX::init(16*16*16,16*16*4);
For(i,1,16)
For(j,1,16)
For(k,1,16){
int r=(i-1)*16*16+(j-1)*16+k;
if (!a[i][j]||a[i][j]==k){
int fir=DLX::cnt+1;
DLX::L[fir]=DLX::cnt;
DLX::R[DLX::cnt]=fir;
}
}
For(i,1,n)
For(j,1,n){
ans[(i-1)*n+j]='Z';
DLX::now[(i-1)*n+j]='Y';
}
int f=DLX::solve();
For(i,1,po){
if (!f)
puts("NO SOLUTION.");
else {
For(i,1,16){
For(j,1,16)
putchar(ans[(i-1)*16+j]);
}
}
puts("");
}
}
int main(){
OPEN(7);
cerr<<"Test 1"<<endl;
solve(1);
cerr<<"Test 2"<<endl;
solve(2);
cerr<<"Test 3"<<endl;
solve(3);
cerr<<"Test 4"<<endl;
solve(4);
return 0;
}
}
namespace P8{
const LL mod=1234567891;
namespace brute{
unsigned long long a,b,c,d,e,f,g,n,q,r,s,t,u,v,w,x,y,z;
unsigned long long p=mod;
int main(int n,LL *A){
a=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0,y=0,z=0,a=0;
while (a<n){
a=a+1,b=0;
while (b<n){
b=b+1,c=0;
while (c<n){
c=c+1,d=0;
while (d<n){
d=d+1,e=0;
while (e<n){
e=e+1,f=0;
while (f<n){
f=f+1,g=0;
while (g<n){
g=g+1;
if (a<b&&b<c&&c<d&&d<e&&e<f&&f<g)
q=(q+1)%p;
if (a<b&&c<g&&c<d&&e<f&&a<d)
r=(r+1)%p;
if (a<d&&d<f&&c<f&&c<e&&b<d)
s=(s+1)%p;
if (d<e&&b<d&&a<f&&d<e&&b<g)
t=(t+1)%p;
if (c<f&&b<f&&b<c&&f<g&&b<f)
u=(u+1)%p;
if (b<d&&b<c&&d<f&&c<e&&b<e)
v=(v+1)%p;
if (a<c&&a<b&&c<e&&b<f&&e<g)
w=(w+1)%p;
if (b<d&&b<f&&a<g&&c<g&&a<e)
x=(x+1)%p;
if (b<f&&a<c&&c<d&&a<c&&b<e)
y=(y+1)%p;
if (d<e&&e<f&&a<d&&c<g&&b<d)
z=(z+1)%p;
}
}
}
}
}
}
}
A[0]=q;
A[1]=r;
A[2]=s;
A[3]=t;
A[4]=u;
A[5]=v;
A[6]=w;
A[7]=x;
A[8]=y;
A[9]=z;
return 0;
}
}
const int N=15;
LL a[N][N];
LL v[N],f[N],F[N],G[N];
if ((x+=y)>=mod)
x-=mod;
}
void Del(LL &x,LL y){
if ((x-=y)<0)
x+=mod;
}
LL Pow(LL x,LL y){
LL ans=1;
for (;y;y>>=1,x=(LL)x*x%mod)
if (y&1)
ans=(LL)ans*x%mod;
return ans;
}
int Calc(int id,int n,int xv){
clr(v),clr(f);
For(i,0,n-1)
v[i]=a[i][id];
For(i,0,n-1){
clr(F);
LL tmp=F[0]=1;
For(j,0,n-1)
if (i!=j)
F[0]=(LL)F[0]*(i-j+mod)%mod;
F[0]=(LL)v[i]*Pow(F[0],mod-2)%mod;
For(j,0,n-1)
if (i!=j){
clr(G);
For(k,0,n-1){
Del(G[k],(LL)F[k]*j%mod);
}
For(k,0,n-1)
F[k]=G[k];
}
For(j,0,n-1)
}
LL tmp=1,res=0;
For(i,0,n-1){
tmp=(LL)tmp*xv%mod;
}
return res;
}
int main(){
OPEN(8);
For(i,0,7)
brute::main(i,a[i]);
For(i,1,10){
cerr<<"Test "<<i<<endl;
cout<<Calc(i-1,8,n)<<endl;
}
return 0;
}
}
namespace P9{
typedef unsigned char UC;
namespace MD5{
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
typedef struct{
unsigned int count[2];
unsigned int state[4];
unsigned char buffer[64];
}MD5_CTX;
#define F(x,y,z) ((x & y) | (~x & z))
#define G(x,y,z) ((x & z) | (y & ~z))
#define H(x,y,z) (x^y^z)
#define I(x,y,z) (y ^ (x | ~z))
#define ROTATE_LEFT(x,n) ((x << n) | (x >> (32-n)))
#define FF(a,b,c,d,x,s,ac) \
{ \
a += F(b,c,d) + x + ac; \
a = ROTATE_LEFT(a,s); \
a += b; \
}
#define GG(a,b,c,d,x,s,ac) \
{ \
a += G(b,c,d) + x + ac; \
a = ROTATE_LEFT(a,s); \
a += b; \
}
#define HH(a,b,c,d,x,s,ac) \
{ \
a += H(b,c,d) + x + ac; \
a = ROTATE_LEFT(a,s); \
a += b; \
}
#define II(a,b,c,d,x,s,ac) \
{ \
a += I(b,c,d) + x + ac; \
a = ROTATE_LEFT(a,s); \
a += b; \
}
void MD5Init(MD5_CTX *context);
void MD5Update(MD5_CTX *context,unsigned char *input,unsigned int inputlen);
void MD5Final(MD5_CTX *context,unsigned char digest[16]);
void MD5Transform(unsigned int state[4],unsigned char block[64]);
void MD5Encode(unsigned char *output,unsigned int *input,unsigned int len);
void MD5Decode(unsigned int *output,unsigned char *input,unsigned int len);

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

void MD5Init(MD5_CTX *context){
context->count[0] = 0;
context->count[1] = 0;
context->state[0] = 0x67452301;
context->state[1] = 0xEFCDAB89;
context->state[3] = 0x10325476;
}
void MD5Update(MD5_CTX *context,unsigned char *input,unsigned int inputlen){
unsigned int i = 0,index = 0,partlen = 0;
index = (context->count[0] >> 3) & 0x3F;
partlen = 64 - index;
context->count[0] += inputlen << 3;
if(context->count[0] < (inputlen << 3))
context->count[1]++;
context->count[1] += inputlen >> 29;

if(inputlen >= partlen){
memcpy(&context->buffer[index],input,partlen);
MD5Transform(context->state,context->buffer);
for(i = partlen;i+64 <= inputlen;i+=64)
MD5Transform(context->state,&input[i]);
index = 0;
}
else
i = 0;
memcpy(&context->buffer[index],&input[i],inputlen-i);
}
void MD5Final(MD5_CTX *context,unsigned char digest[16]){
unsigned int index = 0,padlen = 0;
unsigned char bits[8];
index = (context->count[0] >> 3) & 0x3F;
MD5Encode(bits,context->count,8);
MD5Update(context,bits,8);
MD5Encode(digest,context->state,16);
}
void MD5Encode(unsigned char *output,unsigned int *input,unsigned int len){
unsigned int i = 0,j = 0;
while(j < len){
output[j] = input[i] & 0xFF;
output[j+1] = (input[i] >> 8) & 0xFF;
output[j+2] = (input[i] >> 16) & 0xFF;
output[j+3] = (input[i] >> 24) & 0xFF;
i++;
j+=4;
}
}
void MD5Decode(unsigned int *output,unsigned char *input,unsigned int len){
unsigned int i = 0,j = 0;
while(j < len){
output[i] = (input[j]) |
(input[j+1] << 8) |
(input[j+2] << 16) |
(input[j+3] << 24);
i++;
j+=4;
}
}
void MD5Transform(unsigned int state[4],unsigned char block[64]){
unsigned int a = state[0];
unsigned int b = state[1];
unsigned int c = state[2];
unsigned int d = state[3];
unsigned int x[64];
MD5Decode(x,block,64);
FF(a, b, c, d, x[ 0], 7, 0xd76aa478); /* 1 */
FF(d, a, b, c, x[ 1], 12, 0xe8c7b756); /* 2 */
FF(c, d, a, b, x[ 2], 17, 0x242070db); /* 3 */
FF(b, c, d, a, x[ 3], 22, 0xc1bdceee); /* 4 */
FF(a, b, c, d, x[ 4], 7, 0xf57c0faf); /* 5 */
FF(d, a, b, c, x[ 5], 12, 0x4787c62a); /* 6 */
FF(c, d, a, b, x[ 6], 17, 0xa8304613); /* 7 */
FF(b, c, d, a, x[ 7], 22, 0xfd469501); /* 8 */
FF(a, b, c, d, x[ 8], 7, 0x698098d8); /* 9 */
FF(d, a, b, c, x[ 9], 12, 0x8b44f7af); /* 10 */
FF(c, d, a, b, x[10], 17, 0xffff5bb1); /* 11 */
FF(b, c, d, a, x[11], 22, 0x895cd7be); /* 12 */
FF(a, b, c, d, x[12], 7, 0x6b901122); /* 13 */
FF(d, a, b, c, x[13], 12, 0xfd987193); /* 14 */
FF(c, d, a, b, x[14], 17, 0xa679438e); /* 15 */
FF(b, c, d, a, x[15], 22, 0x49b40821); /* 16 */

/* Round 2 */
GG(a, b, c, d, x[ 1], 5, 0xf61e2562); /* 17 */
GG(d, a, b, c, x[ 6], 9, 0xc040b340); /* 18 */
GG(c, d, a, b, x[11], 14, 0x265e5a51); /* 19 */
GG(b, c, d, a, x[ 0], 20, 0xe9b6c7aa); /* 20 */
GG(a, b, c, d, x[ 5], 5, 0xd62f105d); /* 21 */
GG(d, a, b, c, x[10], 9,  0x2441453); /* 22 */
GG(c, d, a, b, x[15], 14, 0xd8a1e681); /* 23 */
GG(b, c, d, a, x[ 4], 20, 0xe7d3fbc8); /* 24 */
GG(a, b, c, d, x[ 9], 5, 0x21e1cde6); /* 25 */
GG(d, a, b, c, x[14], 9, 0xc33707d6); /* 26 */
GG(c, d, a, b, x[ 3], 14, 0xf4d50d87); /* 27 */
GG(b, c, d, a, x[ 8], 20, 0x455a14ed); /* 28 */
GG(a, b, c, d, x[13], 5, 0xa9e3e905); /* 29 */
GG(d, a, b, c, x[ 2], 9, 0xfcefa3f8); /* 30 */
GG(c, d, a, b, x[ 7], 14, 0x676f02d9); /* 31 */
GG(b, c, d, a, x[12], 20, 0x8d2a4c8a); /* 32 */

/* Round 3 */
HH(a, b, c, d, x[ 5], 4, 0xfffa3942); /* 33 */
HH(d, a, b, c, x[ 8], 11, 0x8771f681); /* 34 */
HH(c, d, a, b, x[11], 16, 0x6d9d6122); /* 35 */
HH(b, c, d, a, x[14], 23, 0xfde5380c); /* 36 */
HH(a, b, c, d, x[ 1], 4, 0xa4beea44); /* 37 */
HH(d, a, b, c, x[ 4], 11, 0x4bdecfa9); /* 38 */
HH(c, d, a, b, x[ 7], 16, 0xf6bb4b60); /* 39 */
HH(b, c, d, a, x[10], 23, 0xbebfbc70); /* 40 */
HH(a, b, c, d, x[13], 4, 0x289b7ec6); /* 41 */
HH(d, a, b, c, x[ 0], 11, 0xeaa127fa); /* 42 */
HH(c, d, a, b, x[ 3], 16, 0xd4ef3085); /* 43 */
HH(b, c, d, a, x[ 6], 23,  0x4881d05); /* 44 */
HH(a, b, c, d, x[ 9], 4, 0xd9d4d039); /* 45 */
HH(d, a, b, c, x[12], 11, 0xe6db99e5); /* 46 */
HH(c, d, a, b, x[15], 16, 0x1fa27cf8); /* 47 */
HH(b, c, d, a, x[ 2], 23, 0xc4ac5665); /* 48 */

/* Round 4 */
II(a, b, c, d, x[ 0], 6, 0xf4292244); /* 49 */
II(d, a, b, c, x[ 7], 10, 0x432aff97); /* 50 */
II(c, d, a, b, x[14], 15, 0xab9423a7); /* 51 */
II(b, c, d, a, x[ 5], 21, 0xfc93a039); /* 52 */
II(a, b, c, d, x[12], 6, 0x655b59c3); /* 53 */
II(d, a, b, c, x[ 3], 10, 0x8f0ccc92); /* 54 */
II(c, d, a, b, x[10], 15, 0xffeff47d); /* 55 */
II(b, c, d, a, x[ 1], 21, 0x85845dd1); /* 56 */
II(a, b, c, d, x[ 8], 6, 0x6fa87e4f); /* 57 */
II(d, a, b, c, x[15], 10, 0xfe2ce6e0); /* 58 */
II(c, d, a, b, x[ 6], 15, 0xa3014314); /* 59 */
II(b, c, d, a, x[13], 21, 0x4e0811a1); /* 60 */
II(a, b, c, d, x[ 4], 6, 0xf7537e82); /* 61 */
II(d, a, b, c, x[11], 10, 0xbd3af235); /* 62 */
II(c, d, a, b, x[ 2], 15, 0x2ad7d2bb); /* 63 */
II(b, c, d, a, x[ 9], 21, 0xeb86d391); /* 64 */
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
}
}
using namespace MD5;
void getMD5(char *IN,int *OU){
static UC s[233],t[233];
clr(s),clr(t);
int len=strlen(IN);
For(i,0,len-1)
s[i]=IN[i];
MD5_CTX md5;
MD5Init(&md5);
MD5Update(&md5,s,len);
MD5Final(&md5,t);
int l2=strlen((char *)t);
For(i,0,l2-1)
OU[i]=t[i];
}
For(i,0,15)
scanf("%2x",&a[i]);
}
int cmpMD5(int *a,int *b){
For(i,0,15)
if (a[i]!=b[i])
return 0;
return 1;
}
void outMD5(int *a){
For(i,0,15)
printf("%02x",a[i]);
puts("");
}
ifstream Dic;
char ans[13][233]={
"",
"1984",
"123456",
"chenlijie",
"",
"",
"",
"",
"",
"",
""
};
int Dic_cnt(){
int len[30];
char s[233];
int res=0,Mxlen=0;
clr(len);
Dic.open("Dictionary");
while (Dic>>s){
res++;
Mxlen=max(Mxlen,(int)strlen(s));
len[(int)strlen(s)]++;
}
Dic.close();
//		outval(Mxlen);
//		outarr(len,1,28);
return res;
}
int a[20],b[20];
const int N=110000;
int n;
char word[N][30];
int len[N];
bool cmp(int a,int b){
return len[a]<len[b];
}
void GetWord(){
static char s[N][30];
static int id[N];
clr(s),clr(id),clr(len);
n=0;
Dic.open("Dictionary");
while (Dic>>s[0]){
n++;
id[n]=n;
len[n]=strlen(s[0]);
For(i,0,len[n]-1)
s[n][i]=s[0][i];
}
Dic.close();
//		sort(id+1,id+n+1,[&](int a,int b){return len[a]<len[b];});
sort(id+1,id+n+1,cmp);
For(i,1,n)
For(j,0,len[id[i]]-1)
word[i][j]=s[id[i]][j];
For(i,1,n)
len[i]=strlen(word[i]);
}
int main(){
//		freopen("i/9.in","r",stdin);
OPEN(9);
//		cout<<Dic_cnt()<<endl;
GetWord();
For(T,1,10){
cerr<<"Test "<<T<<endl;
if (T<=3){
getMD5(ans[T],b);
assert(cmpMD5(a,b));
puts(ans[T]);
}
else if (T==4){
int flag=0;
For(i,32,126){
For(j,32,126){
For(k,32,126){
ans[T][0]=i,ans[T][1]=j,ans[T][2]=k;
getMD5(ans[T],b);
if (cmpMD5(a,b)){
flag=1;
break;
}
}
if (flag)
break;
}
if (flag)
break;
}
assert(flag);
puts(ans[T]);
}
else if (T<=8){
Dic.open("Dictionary");
int flag=0;
while (Dic>>ans[T]){
getMD5(ans[T],b);
if (cmpMD5(a,b)){
flag=1;
break;
}
}
assert(flag);
puts(ans[T]);
Dic.close();
}
else if (T==9){
int flag=0;
For(i,1,n){
For(j,i+1,n){
if (len[i]+len[j]+1>7)
break;
clr(ans[T]);
For(k,0,len[i]-1)
ans[T][k]=word[i][k];
ans[T][len[i]]=' ';
For(k,0,len[j]-1)
ans[T][len[i]+1+k]=word[j][k];
getMD5(ans[T],b);
if (cmpMD5(a,b)){
flag=1;
break;
}
clr(ans[T]);
For(k,0,len[j]-1)
ans[T][k]=word[j][k];
ans[T][len[j]]=' ';
For(k,0,len[i]-1)
ans[T][len[j]+1+k]=word[i][k];
getMD5(ans[T],b);
if (cmpMD5(a,b)){
flag=1;
break;
}
}
if (flag)
break;
}
assert(flag);
puts(ans[T]);
}
else {// it takes about 1 minute to find out this answer
int flag=0;
For(i,1,n){
For(j,i+1,n){
if (len[i]+len[j]>11)
break;
clr(ans[T]);
For(k,0,len[i]-1)
ans[T][k]=word[i][k];
For(k,0,len[j]-1)
ans[T][len[i]+k]=word[j][k];
getMD5(ans[T],b);
if (cmpMD5(a,b)){
flag=1;
break;
}
clr(ans[T]);
For(k,0,len[j]-1)
ans[T][k]=word[j][k];
For(k,0,len[i]-1)
ans[T][len[j]+k]=word[i][k];
getMD5(ans[T],b);
if (cmpMD5(a,b)){
flag=1;
break;
}
}
if (flag)
break;
}
assert(flag);
puts(ans[T]);
}
}
return 0;
}
}
namespace P10{
ifstream Code;
map <string,ULL> C;
char s[1000000];
int n=0;
int cmp(char *a,string b){
int len=b.size();
For(i,0,len-1)
if (a[i]!=b[i])
return 0;
return 1;
}
int Next_void(int it){
while (!cmp(s+it,"void")&&!cmp(s+it,"main"))
it++;
return cmp(s+it,"void")?it+4:it;
}
int isvoid(char c){
return c=='_'||isupper(c);
}
int main(){
OPEN(10);
//		freopen("i/10.in","r",stdin);
Code.open("10.cpp");
string str;
n=1;
while (getline(Code,str)){
int len=str.size();
For(i,0,len-1)
s[n+i]=str[i];
n+=len;
s[n++]='\n';
}
Code.close();
//		puts(s+1);
C.clear();
int it=Next_void(1);
C["_"]=1;
while (!cmp(s+(it=Next_void(it)),"main")){
ULL val=0;
string now="";
while (!isvoid(s[it]))
it++;
do {
now+=s[it];
} while (isvoid(s[++it]));
while (s[it]!='}'){
while (!isvoid(s[it])&&s[it]!='}')
it++;
if (isvoid(s[it])){
string sub="";
do {
sub+=s[it];
} while (isvoid(s[++it]));
val+=C[sub];
}
}
C[now]=val;
//			cout<<"void "<<now<<"() = "<<val<<endl;
}
ULL tmp3=0,tmp2=0;
int cnt=0;
while (!cmp(s+it,"return")){
if (cmp(s+it,"scanf")){
cin>>tmp3;
cerr<<"Test "<<++cnt<<endl;
}
else if (cmp(s+it,"= 0"))
tmp2=0;
else if (isvoid(s[it])){
string now="";
do {
now+=s[it];
} while (isvoid(s[++it]));
tmp2+=C[now];
}
else if (cmp(s+it,"printf"))
cout<<tmp2*tmp3<<endl;
it++;
}
return 0;
}
}
int main(){
#ifdef pAll
P1::main();
P2::main();
P3::main();
P4::main();
P5::main();
P6::main();
P7::main();
P8::main();
P9::main();
P10::main();
#else
#ifdef p1
P1::main();
#endif
#ifdef p2
P2::main();
#endif
#ifdef p3
P3::main();
#endif
#ifdef p4
P4::main();
#endif
#ifdef p5
P5::main();
#endif
#ifdef p6
P6::main();
#endif
#ifdef p7
P7::main();
#endif
#ifdef p8
P8::main();
#endif
#ifdef p9
P9::main();
#endif
#ifdef p10
P10::main();
#endif
#endif
return 0;
}


posted @ 2019-04-17 21:11 -zhouzhendong- 阅读(...) 评论(...) 编辑 收藏