QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#74840#4911. 造数据4182_543_731100 ✓660ms25168kbC++6.9kb2023-02-04 11:43:112023-02-04 11:43:15

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-04 11:43:15]
  • 评测
  • 测评结果:100
  • 用时:660ms
  • 内存:25168kb
  • [2023-02-04 11:43:11]
  • 提交

answer

#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
#define N 413
struct integer{
	typedef long long s64;
	typedef unsigned long long u64;
	typedef unsigned __int128 u128;
	vector<u64> v;
	integer(){}
	integer(u64 x){if(x)v={x};}
	explicit operator bool()const{return !v.empty();}
	explicit operator u64()const{return v.empty()?0:v[0];}
	bool operator ==(const integer &a)const{return v==a.v;}
	bool operator !=(const integer &a)const{return v!=a.v;}
	bool operator <(const integer &a)const
	{
		s64 l1=v.size(),l2=a.v.size();
		if(l1!=l2)return l1<l2;
		while(l1)
		{
			l1--;
			if(v[l1]!=a.v[l1])return v[l1]<a.v[l1];
		}
		return 0;
	}
	bool operator >(const integer &a)const{return a<(*this);}
	bool operator <=(const integer &a)const{return !(a<*this);}
	bool operator >=(const integer &a)const{return !(*this<a);}
	integer &operator <<=(u64 d)
	{
		u64 ci=d>>6,ri=d&63;
		for(u64 i=0;i<ci+1;i++)v.push_back(0);
		for(s64 i=v.size()-1;i>=0;i--)
		{
			u64 as=0;
			if(i>=ci)as|=v[i-ci]<<ri;
			if(i>=ci+1&&ri)as|=v[i-ci-1]>>(64-ri);
			v[i]=as;
		}
		while(v.size()&&v.back()==0)v.pop_back();
		return *this;
	}
	integer &operator >>=(u64 d)
	{
		u64 ci=d>>6,ri=d&63;
		(*this)<<=64-ri;
		for(u64 i=0;i+ci+1<v.size();i++)v[i]=v[i+ci+1];
		for(u64 i=0;i<=ci&&v.size();i++)v.pop_back();
		while(v.size()&&v.back()==0)v.pop_back();
		return *this;
	}
	integer operator <<(u64 d)const{return integer(*this)<<=d;}
	integer operator >>(u64 d)const{return integer(*this)>>=d;}
	integer &operator +=(const integer &a)
	{
		u64 s1=v.size(),s2=a.v.size(),vi=0;
		if(s1<s2)v.resize(s2);
		for(u64 i=0;i<s1||i<s2||vi;i++)
		{
			u128 rs=vi;
			if(i<s1)rs+=v[i];if(i<s2)rs+=a.v[i];
			if(i>=s1&&i>=s2)v.push_back(0);
			vi=(rs>>32)>>32;
			v[i]=rs;
		}
		return *this;
	}
	integer &operator -=(const integer &a)
	{
		u64 s1=v.size(),s2=a.v.size(),vi=0;
		for(u64 i=0;i<s1||i<s2||vi;i++)
		{
			u128 rs=vi;if(vi==-1)rs=-1;
			if(i<s1)rs+=v[i];if(i<s2)rs-=a.v[i];
			if(i>=s1&&i>=s2)v.push_back(0);
			vi=(rs>>32)>>32;
			v[i]=rs;
		}
		while(v.size()&&v.back()==0)v.pop_back();
		return *this;
	}
	integer &operator ++(int){return (*this)+=integer(1);}
	integer &operator --(int){return (*this)-=integer(1);}
	integer operator +(const integer &a){return integer(*this)+=a;}
	integer operator -(const integer &a){return integer(*this)-=a;}
	integer &operator *=(const integer &a)
	{
		vector<u128> tp;
		vector<u64> as;
		u64 s1=v.size(),s2=a.v.size();
		tp.resize(s1+s2+2);as.resize(s1+s2+1);
		for(u64 i=0;i<s1;i++)for(u64 j=0;j<s2;j++)
		{
			u128 si=(u128)v[i]*a.v[j];
			tp[i+j+1]+=(si>>32)>>32;
			tp[i+j]+=(u64)si;
		}
		for(u64 i=0;i+1<tp.size();i++)
		{
			tp[i+1]+=(tp[i]>>32)>>32;
			as[i]=tp[i];
		}
		v=as;
		while(v.size()&&v.back()==0)v.pop_back();
		return *this;
	}
	integer operator *(const integer &a){return integer(*this)*=a;}
	void rem(const integer &a,bool fi)
	{
		u64 vi=a.v.back(),le=(a.v.size()-1)<<6;
		if(le>=64)
		{
			u64 li=__builtin_clzll(vi);
			le-=li;vi=(vi<<li)|(li?a.v[a.v.size()-2]>>(64-li):0);
		}
		if(vi==-1)vi>>=1,le++;
		if(le)vi++;
		integer as;
		while((*this)>=a)
		{
			u128 v1=v.back();u64 l1=(v.size()-1)<<6;
			if(l1)l1-=64,v1=(v1<<32)<<32|v[v.size()-2];
			if(l1<le)v1>>=(le-l1),l1=le;
			u128 ri=v1/vi;
			integer rs,rt;
			u64 t1=(ri>>32)>>32,t2=ri;
			rs.v.push_back(t2);if(t1)rs.v.push_back(t1);
			rt=rs*a;
			rt<<=l1-le;rs<<=l1-le;
			as+=rs;(*this)-=rt;
			if((*this)>=a)*this-=a,as++;
		}
		if(fi)(*this).v=as.v;
	}
	integer &operator /=(const integer &a){rem(a,1);return *this;}
	integer &operator %=(const integer &a){rem(a,0);return *this;}
	integer operator /(const integer &a){return integer(*this)/=a;}
	integer operator %(const integer &a){return integer(*this)%=a;}
	void output()const
	{
		if(v.empty()){printf("0\n");return;}
		bool fg=0;
		for(s64 i=v.size()-1;i>=0;i--)
		{
			u64 si=v[i];
			for(int j=63;j>=0;j--)
			{
				bool tp=(si>>j)&1;
				fg|=tp;
				if(fg)printf("%d",tp);
			}
		}
		printf("\n");
	}
	bool odd()const{return !v.empty()&&(v[0]&1);}
};
#define ll long long
ll bs=1e18;
struct integer2{
	vector<ll> v;
	explicit operator bool()const{return !v.empty();}
	void add(ll a)
	{
		ll rs=a;
		for(int i=0;rs;i++)
		{
			if(i>=v.size())v.push_back(0);
			rs+=v[i];
			v[i]=rs%bs;
			rs/=bs;
		}
	}
	void mul(ll a)
	{
		__int128 rs=0;
		for(int i=0;i<v.size()||rs;i++)
		{
			if(i>=v.size())v.push_back(0);
			rs+=(__int128)a*v[i];
			v[i]=rs%bs;
			rs/=bs;
		}
	}
};
void output(integer a)
{
	integer2 s;
	if(a.v.size())
	for(int i=a.v.size()-1;i>=0;i--)
	{
		s.mul(1ll<<32);s.add(a.v[i]>>32);
		s.mul(1ll<<32);s.add(a.v[i]&((1ll<<32)-1));
	}
	if(!s){printf("0\n");return;}
	printf("%lld",s.v.back());
	for(int i=(int)s.v.size()-2;i>=0;i--)printf("%018lld",s.v[i]);
	printf("\n");
}
struct sth{
	integer v[3][2];
};
bool operator ==(sth a,sth b)
{
	for(int i=0;i<3;i++)for(int j=0;j<2;j++)if(a.v[i][j]!=b.v[i][j])return 0;
	return 1;
}
bool operator <(sth a,sth b)
{
	int fg=0;
	for(int i=0;i<3;i++)for(int j=0;j<2;j++)
	{
		if(a.v[i][j]>b.v[i][j])return 0;
		if(a.v[i][j]<b.v[i][j])fg=1;
	}
	return fg;
}
struct sta{
	sth rv,lv;
	int lx;
};
vector<sta> dp[N][2];
vector<sta> reduce(vector<sta> a)
{
	vector<sta> as;
	for(int i=0;i<a.size();i++)
	{
		int fg=1;
		for(int j=0;j<as.size()&&fg;j++)if(a[i].rv<as[j].rv||a[i].rv==as[j].rv)fg=0;
		for(int j=i+1;j<a.size()&&fg;j++)if(a[i].rv<a[j].rv)fg=0;
		if(fg)as.push_back(a[i]);
	}
	return as;
}
int n,st[N];
int main()
{
	scanf("%d",&n);
	sth fr;for(int i=0;i<3;i++)for(int j=0;j<2;j++)fr.v[i][j]=1;
	sta f1=(sta){fr,fr,0};dp[1][0].push_back(f1);dp[1][1].push_back(f1);
	for(int i=1;i<=n;i++)for(int j=0;j<2;j++)
	{
		dp[i][j]=reduce(dp[i][j]);
		for(int p=0;p<dp[i][j].size();p++)
		{
			sta ri=dp[i][j][p];
			for(int r=0;r<2;r++)
			{
				sta nt;nt.lv=ri.rv;nt.lx=j;
				for(int sx=0;sx<3;sx++)for(int sy=0;sy<2;sy++)
				for(int tx=0;tx<3;tx++)for(int ty=0;ty<2;ty++)
				{
					if(j&&sx<tx)continue;
					if(!j&&sx>tx)continue;
					if(j!=r&&tx!=sy+ty)continue;
					if(sx==0&&sy)continue;
					if(tx==0&&sy+ty)continue;
					if(sx==2&&1-sy)continue;
					if(tx==2&&2-sy-(i+1==n?1:ty))continue;
					if((sx^tx)==2)continue;
					nt.rv.v[tx][ty]+=nt.lv.v[sx][sy];
				}
				dp[i+1][r].push_back(nt);
			}
		}
	}
	integer as=0;
	sta rx;
	for(int t=0;t<2;t++)for(int i=0;i<dp[n][t].size();i++)
	{
		sta r1=dp[n][t][i];
		integer si=r1.rv.v[0][0]+r1.rv.v[1][0]+r1.rv.v[2][0];
		if(si>as)as=si,rx=r1;
	}
	output(as);
	int lb=1,rb=n+1;
	for(int i=n-1;i>=1;i--)
	{
		int ri=rx.lx;
		if(ri)st[n-i]=rb--;else st[n-i]=lb++;
		for(int j=0;j<dp[i][ri].size();j++)if(dp[i][ri][j].rv==rx.lv){rx=dp[i][ri][j];break;}
	}
	st[n]=lb;st[n+1]=rb;
	printf("%d\n",n+1);
	for(int i=1;i<=n;i++)printf("%d %d\n",st[i],st[i+1]);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 3ms
memory: 3040kb

input:

3

output:

13
4
1 2
2 3
3 4

result:

ok Accepted

Test #2:

score: 5
Accepted
time: 2ms
memory: 3144kb

input:

5

output:

59
6
1 2
2 3
3 4
4 5
5 6

result:

ok Accepted

Test #3:

score: 5
Accepted
time: 1ms
memory: 3324kb

input:

7

output:

257
8
1 2
2 3
3 8
8 7
7 6
6 4
4 5

result:

ok Accepted

Test #4:

score: 5
Accepted
time: 3ms
memory: 3216kb

input:

8

output:

557
9
1 2
2 3
3 4
4 9
9 8
8 7
7 5
5 6

result:

ok Accepted

Test #5:

score: 5
Accepted
time: 1ms
memory: 3252kb

input:

9

output:

1210
10
1 2
2 3
3 4
4 10
10 9
9 8
8 7
7 5
5 6

result:

ok Accepted

Test #6:

score: 5
Accepted
time: 4ms
memory: 3376kb

input:

10

output:

2543
11
1 2
2 3
3 4
4 5
5 11
11 10
10 9
9 8
8 6
6 7

result:

ok Accepted

Test #7:

score: 5
Accepted
time: 4ms
memory: 3272kb

input:

11

output:

5349
12
1 2
2 3
3 4
4 5
5 12
12 11
11 10
10 9
9 8
8 6
6 7

result:

ok Accepted

Test #8:

score: 5
Accepted
time: 5ms
memory: 3456kb

input:

15

output:

110617
16
1 2
2 3
3 4
4 5
5 16
16 15
15 14
14 13
13 12
12 6
6 7
7 8
8 9
9 10
10 11

result:

ok Accepted

Test #9:

score: 5
Accepted
time: 13ms
memory: 3832kb

input:

20

output:

4810737
21
1 2
2 3
3 4
4 5
5 21
21 20
20 19
19 18
18 17
17 6
6 7
7 8
8 9
9 10
10 16
16 15
15 14
14 13
13 11
11 12

result:

ok Accepted

Test #10:

score: 5
Accepted
time: 58ms
memory: 5132kb

input:

50

output:

32551381316499551
51
1 2
2 3
3 4
4 5
5 51
51 50
50 49
49 48
48 47
47 6
6 7
7 8
8 9
9 10
10 46
46 45
45 44
44 43
43 42
42 11
11 12
12 13
13 14
14 15
15 41
41 40
40 39
39 38
38 37
37 16
16 17
17 18
18 19
19 20
20 36
36 35
35 34
34 33
33 32
32 21
21 22
22 23
23 24
24 25
25 31
31 30
30 29
29 28
28 26
26...

result:

ok Accepted

Test #11:

score: 5
Accepted
time: 104ms
memory: 6352kb

input:

75

output:

5064471918394716185818793
76
1 2
2 3
3 4
4 5
5 76
76 75
75 74
74 73
73 72
72 6
6 7
7 8
8 9
9 10
10 71
71 70
70 69
69 68
68 67
67 11
11 12
12 13
13 14
14 15
15 66
66 65
65 64
64 63
63 62
62 16
16 17
17 18
18 19
19 20
20 61
61 60
60 59
59 58
58 57
57 21
21 22
22 23
23 24
24 25
25 56
56 55
55 54
54 53
...

result:

ok Accepted

Test #12:

score: 5
Accepted
time: 137ms
memory: 7696kb

input:

100

output:

787950457856847108688588439712081
101
1 2
2 3
3 4
4 5
5 101
101 100
100 99
99 98
98 97
97 6
6 7
7 8
8 9
9 10
10 96
96 95
95 94
94 93
93 92
92 11
11 12
12 13
13 14
14 15
15 91
91 90
90 89
89 88
88 87
87 16
16 17
17 18
18 19
19 20
20 86
86 85
85 84
84 83
83 82
82 21
21 22
22 23
23 24
24 25
25 81
81 80...

result:

ok Accepted

Test #13:

score: 5
Accepted
time: 245ms
memory: 10104kb

input:

150

output:

19073412522807805936171451101046180484374166698119
151
1 2
2 3
3 4
4 5
5 151
151 150
150 149
149 148
148 147
147 6
6 7
7 8
8 9
9 10
10 146
146 145
145 144
144 143
143 142
142 11
11 12
12 13
13 14
14 15
15 141
141 140
140 139
139 138
138 137
137 16
16 17
17 18
18 19
19 20
20 136
136 135
135 134
134 1...

result:

ok Accepted

Test #14:

score: 5
Accepted
time: 306ms
memory: 12584kb

input:

200

output:

461697891837883823312995599879277757576207826948506333740022403033
201
1 2
2 3
3 4
4 5
5 201
201 200
200 199
199 198
198 197
197 6
6 7
7 8
8 9
9 10
10 196
196 195
195 194
194 193
193 192
192 11
11 12
12 13
13 14
14 15
15 191
191 190
190 189
189 188
188 187
187 16
16 17
17 18
18 19
19 20
20 186
186 1...

result:

ok Accepted

Test #15:

score: 5
Accepted
time: 394ms
memory: 15656kb

input:

250

output:

11176025426632263675257706835434503730284986749237624935226969853832799786507751823
251
1 2
2 3
3 4
4 5
5 251
251 250
250 249
249 248
248 247
247 6
6 7
7 8
8 9
9 10
10 246
246 245
245 244
244 243
243 242
242 11
11 12
12 13
13 14
14 15
15 241
241 240
240 239
239 238
238 237
237 16
16 17
17 18
18 19
1...

result:

ok Accepted

Test #16:

score: 5
Accepted
time: 491ms
memory: 18756kb

input:

300

output:

270530895949137896052201331765919757216413091197338466873020277503414507400039934629539976268189057
301
1 2
2 3
3 4
4 5
5 301
301 300
300 299
299 298
298 297
297 6
6 7
7 8
8 9
9 10
10 296
296 295
295 294
294 293
293 292
292 11
11 12
12 13
13 14
14 15
15 291
291 290
290 289
289 288
288 287
287 16
16 ...

result:

ok Accepted

Test #17:

score: 5
Accepted
time: 518ms
memory: 20244kb

input:

325

output:

42090260694961674145011704114080973238245161078623315982050154741567608589212648207015261493973771450688875
326
1 2
2 3
3 4
4 5
5 326
326 325
325 324
324 323
323 322
322 6
6 7
7 8
8 9
9 10
10 321
321 320
320 319
319 318
318 317
317 11
11 12
12 13
13 14
14 15
15 316
316 315
315 314
314 313
313 312
31...

result:

ok Accepted

Test #18:

score: 5
Accepted
time: 601ms
memory: 21928kb

input:

350

output:

6548568285165142665992191689091774699104268412094134278757549209751675845382090202485775517538726036924104490839159
351
1 2
2 3
3 4
4 5
5 351
351 350
350 349
349 348
348 347
347 6
6 7
7 8
8 9
9 10
10 346
346 345
345 344
344 343
343 342
342 11
11 12
12 13
13 14
14 15
15 341
341 340
340 339
339 338
33...

result:

ok Accepted

Test #19:

score: 5
Accepted
time: 612ms
memory: 23604kb

input:

375

output:

1018852007029836374581686608753588256606780138614351080335745613231231502577350362525622040527404062058174015555297345988697
376
1 2
2 3
3 4
4 5
5 376
376 375
375 374
374 373
373 372
372 6
6 7
7 8
8 9
9 10
10 371
371 370
370 369
369 368
368 367
367 11
11 12
12 13
13 14
14 15
15 366
366 365
365 364
3...

result:

ok Accepted

Test #20:

score: 5
Accepted
time: 660ms
memory: 25168kb

input:

400

output:

158517002041545914631471235811957888138755459976466905885841583972694007539220127367241456471218479364602339492642236309561813645129
401
1 2
2 3
3 4
4 5
5 401
401 400
400 399
399 398
398 397
397 6
6 7
7 8
8 9
9 10
10 396
396 395
395 394
394 393
393 392
392 11
11 12
12 13
13 14
14 15
15 391
391 390
3...

result:

ok Accepted