QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#500669#3822. AnagramsPetroTarnavskyi#AC ✓21ms3908kbC++201.2kb2024-08-01 17:40:122024-08-01 17:40:13

Judging History

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

  • [2024-08-01 17:40:13]
  • 评测
  • 测评结果:AC
  • 用时:21ms
  • 内存:3908kb
  • [2024-08-01 17:40:12]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int MAGIC = 21;

LL fact[MAGIC];
unordered_set<LL> s[MAGIC];
LL maxDen[MAGIC];

void rec(int sum, int last, LL prod)
{
	assert(sum < MAGIC);
	s[sum].insert(prod);
	maxDen[sum] = max(maxDen[sum], prod);
	FOR(x, last, MAGIC - sum)
		rec(sum + x, x, prod * fact[x]);
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	fact[0] = 1;
	FOR(i, 1, MAGIC)
	{
		fact[i] = fact[i - 1] * i;
	}
	rec(0, 1, 1);
	LL n;
	cin >> n;
	LL ans = n;
	FOR(sum, 2, MAGIC)
	{
		__int128 num = fact[sum];
		for (LL k = sum; ; k++)
		{
			__int128 d = num / n;
			if (d > maxDen[sum])
				break;
			if (num % n == 0 && s[sum].count(d))
				ans = min(ans, k);
			num = num / (k - sum + 1) * (k + 1);
		}
	}
	cout << ans << "\n";
	return 0;
}


这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3608kb

input:

12

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 17ms
memory: 3608kb

input:

627222906373

output:

627222906373

result:

ok 1 number(s): "627222906373"

Test #3:

score: 0
Accepted
time: 7ms
memory: 3628kb

input:

91008809464

output:

91008809464

result:

ok 1 number(s): "91008809464"

Test #4:

score: 0
Accepted
time: 21ms
memory: 3904kb

input:

967068301613

output:

967068301613

result:

ok 1 number(s): "967068301613"

Test #5:

score: 0
Accepted
time: 17ms
memory: 3620kb

input:

668686722322

output:

668686722322

result:

ok 1 number(s): "668686722322"

Test #6:

score: 0
Accepted
time: 1ms
memory: 3684kb

input:

1666636245

output:

57735

result:

ok 1 number(s): "57735"

Test #7:

score: 0
Accepted
time: 11ms
memory: 3664kb

input:

263436006870

output:

725860

result:

ok 1 number(s): "725860"

Test #8:

score: 0
Accepted
time: 4ms
memory: 3892kb

input:

34576741935

output:

262971

result:

ok 1 number(s): "262971"

Test #9:

score: 0
Accepted
time: 15ms
memory: 3864kb

input:

491196594903

output:

991158

result:

ok 1 number(s): "991158"

Test #10:

score: 0
Accepted
time: 8ms
memory: 3596kb

input:

123970379016

output:

497937

result:

ok 1 number(s): "497937"

Test #11:

score: 0
Accepted
time: 11ms
memory: 3696kb

input:

277860896778

output:

745468

result:

ok 1 number(s): "745468"

Test #12:

score: 0
Accepted
time: 12ms
memory: 3720kb

input:

292418604631

output:

764747

result:

ok 1 number(s): "764747"

Test #13:

score: 0
Accepted
time: 1ms
memory: 3564kb

input:

88411753

output:

13298

result:

ok 1 number(s): "13298"

Test #14:

score: 0
Accepted
time: 4ms
memory: 3564kb

input:

30051835380

output:

245161

result:

ok 1 number(s): "245161"

Test #15:

score: 0
Accepted
time: 7ms
memory: 3608kb

input:

110021541328

output:

469088

result:

ok 1 number(s): "469088"

Test #16:

score: 0
Accepted
time: 3ms
memory: 3892kb

input:

15602169628

output:

176648

result:

ok 1 number(s): "176648"

Test #17:

score: 0
Accepted
time: 2ms
memory: 3604kb

input:

5154928580

output:

3140

result:

ok 1 number(s): "3140"

Test #18:

score: 0
Accepted
time: 8ms
memory: 3692kb

input:

126591508250

output:

9125

result:

ok 1 number(s): "9125"

Test #19:

score: 0
Accepted
time: 1ms
memory: 3828kb

input:

40495000

output:

625

result:

ok 1 number(s): "625"

Test #20:

score: 0
Accepted
time: 3ms
memory: 3608kb

input:

10523313031

output:

3983

result:

ok 1 number(s): "3983"

Test #21:

score: 0
Accepted
time: 5ms
memory: 3676kb

input:

47828931690

output:

6597

result:

ok 1 number(s): "6597"

Test #22:

score: 0
Accepted
time: 1ms
memory: 3672kb

input:

593424776

output:

1528

result:

ok 1 number(s): "1528"

Test #23:

score: 0
Accepted
time: 1ms
memory: 3888kb

input:

4822356

output:

308

result:

ok 1 number(s): "308"

Test #24:

score: 0
Accepted
time: 6ms
memory: 3888kb

input:

166017509636

output:

9988

result:

ok 1 number(s): "9988"

Test #25:

score: 0
Accepted
time: 3ms
memory: 3688kb

input:

13030522050

output:

4277

result:

ok 1 number(s): "4277"

Test #26:

score: 0
Accepted
time: 1ms
memory: 3628kb

input:

1391641251

output:

429

result:

ok 1 number(s): "429"

Test #27:

score: 0
Accepted
time: 1ms
memory: 3716kb

input:

40432700

output:

178

result:

ok 1 number(s): "178"

Test #28:

score: 0
Accepted
time: 1ms
memory: 3696kb

input:

1019454315

output:

397

result:

ok 1 number(s): "397"

Test #29:

score: 0
Accepted
time: 0ms
memory: 3692kb

input:

69300

output:

11

result:

ok 1 number(s): "11"

Test #30:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

1

output:

1

result:

ok 1 number(s): "1"

Test #31:

score: 0
Accepted
time: 1ms
memory: 3668kb

input:

857656800

output:

17

result:

ok 1 number(s): "17"

Test #32:

score: 0
Accepted
time: 12ms
memory: 3824kb

input:

288425561243

output:

288425561243

result:

ok 1 number(s): "288425561243"

Test #33:

score: 0
Accepted
time: 3ms
memory: 3620kb

input:

14665931280

output:

19

result:

ok 1 number(s): "19"

Test #34:

score: 0
Accepted
time: 5ms
memory: 3608kb

input:

41902660800

output:

19

result:

ok 1 number(s): "19"

Test #35:

score: 0
Accepted
time: 9ms
memory: 3676kb

input:

293318625600

output:

19

result:

ok 1 number(s): "19"

Test #36:

score: 0
Accepted
time: 3ms
memory: 3632kb

input:

17298277920

output:

23

result:

ok 1 number(s): "23"

Test #37:

score: 0
Accepted
time: 8ms
memory: 3832kb

input:

133855722000

output:

25

result:

ok 1 number(s): "25"

Test #38:

score: 0
Accepted
time: 1ms
memory: 3620kb

input:

1740538800

output:

28

result:

ok 1 number(s): "28"

Test #39:

score: 0
Accepted
time: 15ms
memory: 3676kb

input:

511377867000

output:

55

result:

ok 1 number(s): "55"

Test #40:

score: 0
Accepted
time: 7ms
memory: 3608kb

input:

85229644500

output:

55

result:

ok 1 number(s): "55"

Test #41:

score: 0
Accepted
time: 11ms
memory: 3824kb

input:

244432188000

output:

19

result:

ok 1 number(s): "19"

Test #42:

score: 0
Accepted
time: 1ms
memory: 3612kb

input:

17153136

output:

18

result:

ok 1 number(s): "18"

Test #43:

score: 0
Accepted
time: 1ms
memory: 3864kb

input:

5405400

output:

13

result:

ok 1 number(s): "13"

Test #44:

score: 0
Accepted
time: 1ms
memory: 3604kb

input:

514594080

output:

17

result:

ok 1 number(s): "17"

Test #45:

score: 0
Accepted
time: 1ms
memory: 3560kb

input:

720720

output:

13

result:

ok 1 number(s): "13"

Test #46:

score: 0
Accepted
time: 0ms
memory: 3888kb

input:

50450400

output:

14

result:

ok 1 number(s): "14"

Test #47:

score: 0
Accepted
time: 18ms
memory: 3904kb

input:

684410126400

output:

21

result:

ok 1 number(s): "21"

Test #48:

score: 0
Accepted
time: 1ms
memory: 3612kb

input:

831600

output:

11

result:

ok 1 number(s): "11"

Test #49:

score: 0
Accepted
time: 1ms
memory: 3624kb

input:

14414400

output:

13

result:

ok 1 number(s): "13"

Test #50:

score: 0
Accepted
time: 0ms
memory: 3692kb

input:

1681680

output:

14

result:

ok 1 number(s): "14"

Test #51:

score: 0
Accepted
time: 0ms
memory: 3676kb

input:

220540320

output:

18

result:

ok 1 number(s): "18"

Test #52:

score: 0
Accepted
time: 0ms
memory: 3860kb

input:

720720

output:

13

result:

ok 1 number(s): "13"

Test #53:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

1512

output:

9

result:

ok 1 number(s): "9"

Test #54:

score: 0
Accepted
time: 1ms
memory: 3892kb

input:

180

output:

6

result:

ok 1 number(s): "6"

Test #55:

score: 0
Accepted
time: 1ms
memory: 3824kb

input:

88216128

output:

18

result:

ok 1 number(s): "18"

Test #56:

score: 0
Accepted
time: 1ms
memory: 3672kb

input:

220540320

output:

18

result:

ok 1 number(s): "18"

Test #57:

score: 0
Accepted
time: 1ms
memory: 3556kb

input:

23876160

output:

22

result:

ok 1 number(s): "22"

Test #58:

score: 0
Accepted
time: 1ms
memory: 3556kb

input:

1544489100

output:

25

result:

ok 1 number(s): "25"

Test #59:

score: 0
Accepted
time: 4ms
memory: 3696kb

input:

20593188000

output:

25

result:

ok 1 number(s): "25"

Test #60:

score: 0
Accepted
time: 1ms
memory: 3828kb

input:

91891800

output:

17

result:

ok 1 number(s): "17"

Test #61:

score: 0
Accepted
time: 11ms
memory: 3672kb

input:

247118256000

output:

25

result:

ok 1 number(s): "25"

Test #62:

score: 0
Accepted
time: 1ms
memory: 3696kb

input:

1102701600

output:

17

result:

ok 1 number(s): "17"

Test #63:

score: 0
Accepted
time: 1ms
memory: 3900kb

input:

504504000

output:

15

result:

ok 1 number(s): "15"

Test #64:

score: 0
Accepted
time: 1ms
memory: 3672kb

input:

4989600

output:

11

result:

ok 1 number(s): "11"

Test #65:

score: 0
Accepted
time: 3ms
memory: 3860kb

input:

10291881600

output:

17

result:

ok 1 number(s): "17"

Test #66:

score: 0
Accepted
time: 4ms
memory: 3672kb

input:

30875644800

output:

17

result:

ok 1 number(s): "17"

Test #67:

score: 0
Accepted
time: 1ms
memory: 3668kb

input:

1396755360

output:

19

result:

ok 1 number(s): "19"

Test #68:

score: 0
Accepted
time: 0ms
memory: 3636kb

input:

100800

output:

10

result:

ok 1 number(s): "10"

Test #69:

score: 0
Accepted
time: 1ms
memory: 3592kb

input:

367567200

output:

17

result:

ok 1 number(s): "17"

Test #70:

score: 0
Accepted
time: 1ms
memory: 3616kb

input:

75675600

output:

14

result:

ok 1 number(s): "14"

Test #71:

score: 0
Accepted
time: 14ms
memory: 3560kb

input:

411675264000

output:

17

result:

ok 1 number(s): "17"

Test #72:

score: 0
Accepted
time: 3ms
memory: 3908kb

input:

18162144000

output:

15

result:

ok 1 number(s): "15"

Test #73:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

302400

output:

10

result:

ok 1 number(s): "10"

Test #74:

score: 0
Accepted
time: 1ms
memory: 3832kb

input:

4989600

output:

11

result:

ok 1 number(s): "11"

Test #75:

score: 0
Accepted
time: 2ms
memory: 3672kb

input:

3223281600

output:

22

result:

ok 1 number(s): "22"

Test #76:

score: 0
Accepted
time: 13ms
memory: 3692kb

input:

620159379840

output:

39

result:

ok 1 number(s): "39"

Test #77:

score: 0
Accepted
time: 2ms
memory: 3676kb

input:

22378356000

output:

27

result:

ok 1 number(s): "27"

Test #78:

score: 0
Accepted
time: 18ms
memory: 3612kb

input:

697121045460

output:

63

result:

ok 1 number(s): "63"

Test #79:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

1118917800

output:

27

result:

ok 1 number(s): "27"

Test #80:

score: 0
Accepted
time: 8ms
memory: 3620kb

input:

125854344000

output:

50

result:

ok 1 number(s): "50"

Test #81:

score: 0
Accepted
time: 1ms
memory: 3856kb

input:

110270160

output:

18

result:

ok 1 number(s): "18"

Test #82:

score: 0
Accepted
time: 1ms
memory: 3680kb

input:

83160

output:

11

result:

ok 1 number(s): "11"

Test #83:

score: 0
Accepted
time: 1ms
memory: 3668kb

input:

127125600

output:

50

result:

ok 1 number(s): "50"

Test #84:

score: 0
Accepted
time: 4ms
memory: 3896kb

input:

19879587000

output:

31

result:

ok 1 number(s): "31"

Test #85:

score: 0
Accepted
time: 6ms
memory: 3616kb

input:

63029126160

output:

82

result:

ok 1 number(s): "82"

Test #86:

score: 0
Accepted
time: 20ms
memory: 3560kb

input:

886528219500

output:

126

result:

ok 1 number(s): "126"

Test #87:

score: 0
Accepted
time: 20ms
memory: 3904kb

input:

886528219500

output:

126

result:

ok 1 number(s): "126"

Test #88:

score: 0
Accepted
time: 18ms
memory: 3668kb

input:

961935906662

output:

961935906662

result:

ok 1 number(s): "961935906662"

Test #89:

score: 0
Accepted
time: 1ms
memory: 3636kb

input:

350602560

output:

36

result:

ok 1 number(s): "36"

Test #90:

score: 0
Accepted
time: 1ms
memory: 3672kb

input:

149059680

output:

112

result:

ok 1 number(s): "112"

Test #91:

score: 0
Accepted
time: 1ms
memory: 3596kb

input:

132530580

output:

31

result:

ok 1 number(s): "31"

Test #92:

score: 0
Accepted
time: 1ms
memory: 3824kb

input:

44963880

output:

41

result:

ok 1 number(s): "41"

Test #93:

score: 0
Accepted
time: 1ms
memory: 3676kb

input:

17297280

output:

14

result:

ok 1 number(s): "14"

Test #94:

score: 0
Accepted
time: 5ms
memory: 3688kb

input:

50033283300

output:

79

result:

ok 1 number(s): "79"

Test #95:

score: 0
Accepted
time: 1ms
memory: 3624kb

input:

1203490860

output:

223

result:

ok 1 number(s): "223"

Test #96:

score: 0
Accepted
time: 14ms
memory: 3604kb

input:

436286217267

output:

436286217267

result:

ok 1 number(s): "436286217267"

Test #97:

score: 0
Accepted
time: 18ms
memory: 3560kb

input:

999035776528

output:

999035776528

result:

ok 1 number(s): "999035776528"

Test #98:

score: 0
Accepted
time: 19ms
memory: 3608kb

input:

756700255392

output:

756700255392

result:

ok 1 number(s): "756700255392"

Test #99:

score: 0
Accepted
time: 14ms
memory: 3692kb

input:

435655010199

output:

435655010199

result:

ok 1 number(s): "435655010199"

Test #100:

score: 0
Accepted
time: 4ms
memory: 3692kb

input:

25776078300

output:

478

result:

ok 1 number(s): "478"

Test #101:

score: 0
Accepted
time: 1ms
memory: 3688kb

input:

604858980

output:

188

result:

ok 1 number(s): "188"

Test #102:

score: 0
Accepted
time: 1ms
memory: 3904kb

input:

337155390

output:

69

result:

ok 1 number(s): "69"

Test #103:

score: 0
Accepted
time: 5ms
memory: 3696kb

input:

36546542370

output:

173

result:

ok 1 number(s): "173"

Test #104:

score: 0
Accepted
time: 18ms
memory: 3664kb

input:

727309905660

output:

313

result:

ok 1 number(s): "313"

Test #105:

score: 0
Accepted
time: 1ms
memory: 3620kb

input:

131040

output:

16

result:

ok 1 number(s): "16"

Test #106:

score: 0
Accepted
time: 11ms
memory: 3564kb

input:

269128937220

output:

41

result:

ok 1 number(s): "41"