QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#181224#7225. The Kirakira Cycleucup-team288#AC ✓1412ms226880kbC++202.4kb2023-09-16 16:52:172023-09-16 16:52:19

Judging History

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

  • [2023-09-16 16:52:19]
  • 评测
  • 测评结果:AC
  • 用时:1412ms
  • 内存:226880kb
  • [2023-09-16 16:52:17]
  • 提交

answer

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
using i64 = long long;

constexpr int N = 51000000;
int primes[3000847 + 2], pl;
int f[N + 1], *minp = f;//[N + 1];
//int f[N+1], minp[N+1];
bitset<N> vis, die;

void chmax(auto &a, auto b) { a = max(a, b); }
int main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	int n;
	cin >> n;
	//cout << (sizeof(primes) + sizeof(f) + sizeof(minp)) / 1000000 << endl;

	for (int i = 2; i <= n * (n - 1) / 2; i++) {
		if (!minp[i]) {
			//primes.push_back(i);
			primes[pl++] = i;
			minp[i] = i;
		}
	
		for (int p : primes) {
			if (p > n * (n - 1) / 2 / i) {
				break;
			}
			minp[p * i] = p;
			if (i % p == 0) {
				break;
			}
		}
	}
	//fill(f, f + N + 1, 0);
	memset(f, 0, sizeof(f));
	//memset(f, sizeof(f), 0);

	for (int i = 1; i <= n; i++) {
		f[i] = -i;
	}

	//for (auto p : primes) {
	for (int i = 0;i < pl;++i) {
		int p = primes[i];
		for (int i = 1; p * i <= n * (n - 1) / 2; i++) {
			f[p * i] += f[i];
		}
	}

	for (int i = 1; i <= n * (n - 1) / 2; i++) {
		f[i] += f[i - 1];
		f[i] += n;
	}

	int m = n * (n - 1) / 2;

	int ans = 1;

	for (int i = 0;i <= m;++i) {
		if (die[i]) continue;
		int u = i;
		while (!vis[u]) {
			vis[u] = true;
			u = f[u];
			if (die[u]) break;
		}
		u = f[u];
		if (!die[u]) { 
			//DE(u);
			int c = 0, v = u;
			do {
				v = f[v];
				++c;
				DE(v);
			} while (v != u);
			ans = max(ans, c);
		}
		u = i;
		while (!die[u]) {
			die[u] = true;
			u = f[u];
		}
	}


//	for (int i = 1; i <= m; i++) {
//		if (vis[i] == 0) {
//			int u = i;
//			while (vis[u] != i) {
//				vis[u] = i;
//				u = f[u];
//			}
//			if (vis[u] == i) {
//				int c = 0, v = u;
//				do {
//					v = f[v];
//					c++;
//				} while (v != u);
//				ans = max(ans, c);
//			}
//		}
//	}

	cout << ans << '\n';
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 11ms
memory: 206368kb

input:

2

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

10

output:

4

result:

ok 1 number(s): "4"

Test #3:

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

input:

43

output:

7

result:

ok 1 number(s): "7"

Test #4:

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

input:

1

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

input:

3

output:

1

result:

ok 1 number(s): "1"

Test #6:

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

input:

4

output:

3

result:

ok 1 number(s): "3"

Test #7:

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

input:

5

output:

2

result:

ok 1 number(s): "2"

Test #8:

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

input:

6

output:

2

result:

ok 1 number(s): "2"

Test #9:

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

input:

7

output:

1

result:

ok 1 number(s): "1"

Test #10:

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

input:

8

output:

3

result:

ok 1 number(s): "3"

Test #11:

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

input:

9

output:

2

result:

ok 1 number(s): "2"

Test #12:

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

input:

11

output:

7

result:

ok 1 number(s): "7"

Test #13:

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

input:

13

output:

6

result:

ok 1 number(s): "6"

Test #14:

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

input:

17

output:

4

result:

ok 1 number(s): "4"

Test #15:

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

input:

19

output:

5

result:

ok 1 number(s): "5"

Test #16:

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

input:

23

output:

3

result:

ok 1 number(s): "3"

Test #17:

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

input:

29

output:

2

result:

ok 1 number(s): "2"

Test #18:

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

input:

31

output:

13

result:

ok 1 number(s): "13"

Test #19:

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

input:

37

output:

5

result:

ok 1 number(s): "5"

Test #20:

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

input:

41

output:

21

result:

ok 1 number(s): "21"

Test #21:

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

input:

60

output:

8

result:

ok 1 number(s): "8"

Test #22:

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

input:

100

output:

11

result:

ok 1 number(s): "11"

Test #23:

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

input:

105

output:

41

result:

ok 1 number(s): "41"

Test #24:

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

input:

128

output:

31

result:

ok 1 number(s): "31"

Test #25:

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

input:

130

output:

25

result:

ok 1 number(s): "25"

Test #26:

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

input:

256

output:

52

result:

ok 1 number(s): "52"

Test #27:

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

input:

290

output:

15

result:

ok 1 number(s): "15"

Test #28:

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

input:

455

output:

104

result:

ok 1 number(s): "104"

Test #29:

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

input:

512

output:

45

result:

ok 1 number(s): "45"

Test #30:

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

input:

777

output:

35

result:

ok 1 number(s): "35"

Test #31:

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

input:

707

output:

175

result:

ok 1 number(s): "175"

Test #32:

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

input:

449

output:

13

result:

ok 1 number(s): "13"

Test #33:

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

input:

573

output:

168

result:

ok 1 number(s): "168"

Test #34:

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

input:

858

output:

49

result:

ok 1 number(s): "49"

Test #35:

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

input:

230

output:

58

result:

ok 1 number(s): "58"

Test #36:

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

input:

972

output:

117

result:

ok 1 number(s): "117"

Test #37:

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

input:

844

output:

47

result:

ok 1 number(s): "47"

Test #38:

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

input:

378

output:

37

result:

ok 1 number(s): "37"

Test #39:

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

input:

423

output:

49

result:

ok 1 number(s): "49"

Test #40:

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

input:

209

output:

20

result:

ok 1 number(s): "20"

Test #41:

score: 0
Accepted
time: 339ms
memory: 212460kb

input:

5645

output:

338

result:

ok 1 number(s): "338"

Test #42:

score: 0
Accepted
time: 45ms
memory: 203948kb

input:

2034

output:

249

result:

ok 1 number(s): "249"

Test #43:

score: 0
Accepted
time: 437ms
memory: 212328kb

input:

6163

output:

206

result:

ok 1 number(s): "206"

Test #44:

score: 0
Accepted
time: 488ms
memory: 213912kb

input:

6422

output:

346

result:

ok 1 number(s): "346"

Test #45:

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

input:

1550

output:

40

result:

ok 1 number(s): "40"

Test #46:

score: 0
Accepted
time: 596ms
memory: 216144kb

input:

6940

output:

674

result:

ok 1 number(s): "674"

Test #47:

score: 0
Accepted
time: 32ms
memory: 204056kb

input:

2068

output:

157

result:

ok 1 number(s): "157"

Test #48:

score: 0
Accepted
time: 453ms
memory: 212504kb

input:

6197

output:

594

result:

ok 1 number(s): "594"

Test #49:

score: 0
Accepted
time: 509ms
memory: 214844kb

input:

6456

output:

913

result:

ok 1 number(s): "913"

Test #50:

score: 0
Accepted
time: 1023ms
memory: 222396kb

input:

8776

output:

423

result:

ok 1 number(s): "423"

Test #51:

score: 0
Accepted
time: 139ms
memory: 206752kb

input:

3904

output:

281

result:

ok 1 number(s): "281"

Test #52:

score: 0
Accepted
time: 163ms
memory: 208904kb

input:

4163

output:

230

result:

ok 1 number(s): "230"

Test #53:

score: 0
Accepted
time: 192ms
memory: 208832kb

input:

4422

output:

631

result:

ok 1 number(s): "631"

Test #54:

score: 0
Accepted
time: 220ms
memory: 208860kb

input:

4681

output:

95

result:

ok 1 number(s): "95"

Test #55:

score: 0
Accepted
time: 1046ms
memory: 222392kb

input:

8810

output:

835

result:

ok 1 number(s): "835"

Test #56:

score: 0
Accepted
time: 128ms
memory: 208436kb

input:

3938

output:

350

result:

ok 1 number(s): "350"

Test #57:

score: 0
Accepted
time: 1146ms
memory: 224644kb

input:

9328

output:

373

result:

ok 1 number(s): "373"

Test #58:

score: 0
Accepted
time: 178ms
memory: 209676kb

input:

4456

output:

932

result:

ok 1 number(s): "932"

Test #59:

score: 0
Accepted
time: 207ms
memory: 209824kb

input:

4715

output:

476

result:

ok 1 number(s): "476"

Test #60:

score: 0
Accepted
time: 729ms
memory: 218692kb

input:

7633

output:

591

result:

ok 1 number(s): "591"

Test #61:

score: 0
Accepted
time: 72ms
memory: 204924kb

input:

2762

output:

263

result:

ok 1 number(s): "263"

Test #62:

score: 0
Accepted
time: 841ms
memory: 219524kb

input:

8152

output:

465

result:

ok 1 number(s): "465"

Test #63:

score: 0
Accepted
time: 93ms
memory: 205616kb

input:

3280

output:

157

result:

ok 1 number(s): "157"

Test #64:

score: 0
Accepted
time: 103ms
memory: 206728kb

input:

3539

output:

79

result:

ok 1 number(s): "79"

Test #65:

score: 0
Accepted
time: 729ms
memory: 218784kb

input:

7668

output:

905

result:

ok 1 number(s): "905"

Test #66:

score: 0
Accepted
time: 788ms
memory: 219036kb

input:

7927

output:

357

result:

ok 1 number(s): "357"

Test #67:

score: 0
Accepted
time: 888ms
memory: 219824kb

input:

8186

output:

543

result:

ok 1 number(s): "543"

Test #68:

score: 0
Accepted
time: 84ms
memory: 207484kb

input:

3314

output:

306

result:

ok 1 number(s): "306"

Test #69:

score: 0
Accepted
time: 112ms
memory: 207876kb

input:

3573

output:

69

result:

ok 1 number(s): "69"

Test #70:

score: 0
Accepted
time: 588ms
memory: 215740kb

input:

6873

output:

667

result:

ok 1 number(s): "667"

Test #71:

score: 0
Accepted
time: 40ms
memory: 204008kb

input:

2001

output:

134

result:

ok 1 number(s): "134"

Test #72:

score: 0
Accepted
time: 711ms
memory: 217052kb

input:

7391

output:

477

result:

ok 1 number(s): "477"

Test #73:

score: 0
Accepted
time: 51ms
memory: 204540kb

input:

2519

output:

267

result:

ok 1 number(s): "267"

Test #74:

score: 0
Accepted
time: 71ms
memory: 204848kb

input:

2778

output:

162

result:

ok 1 number(s): "162"

Test #75:

score: 0
Accepted
time: 75ms
memory: 206860kb

input:

3037

output:

282

result:

ok 1 number(s): "282"

Test #76:

score: 0
Accepted
time: 88ms
memory: 205640kb

input:

3296

output:

458

result:

ok 1 number(s): "458"

Test #77:

score: 0
Accepted
time: 696ms
memory: 216308kb

input:

7426

output:

214

result:

ok 1 number(s): "214"

Test #78:

score: 0
Accepted
time: 56ms
memory: 204556kb

input:

2554

output:

102

result:

ok 1 number(s): "102"

Test #79:

score: 0
Accepted
time: 800ms
memory: 218464kb

input:

7944

output:

283

result:

ok 1 number(s): "283"

Test #80:

score: 0
Accepted
time: 440ms
memory: 212956kb

input:

6113

output:

121

result:

ok 1 number(s): "121"

Test #81:

score: 0
Accepted
time: 1342ms
memory: 226784kb

input:

10000

output:

917

result:

ok 1 number(s): "917"

Test #82:

score: 0
Accepted
time: 1345ms
memory: 226828kb

input:

9999

output:

470

result:

ok 1 number(s): "470"

Test #83:

score: 0
Accepted
time: 1330ms
memory: 226856kb

input:

9998

output:

1552

result:

ok 1 number(s): "1552"

Test #84:

score: 0
Accepted
time: 1342ms
memory: 226696kb

input:

9997

output:

538

result:

ok 1 number(s): "538"

Test #85:

score: 0
Accepted
time: 1327ms
memory: 226768kb

input:

9996

output:

193

result:

ok 1 number(s): "193"

Test #86:

score: 0
Accepted
time: 1325ms
memory: 226688kb

input:

9995

output:

624

result:

ok 1 number(s): "624"

Test #87:

score: 0
Accepted
time: 1328ms
memory: 226832kb

input:

9994

output:

481

result:

ok 1 number(s): "481"

Test #88:

score: 0
Accepted
time: 1353ms
memory: 226832kb

input:

9993

output:

617

result:

ok 1 number(s): "617"

Test #89:

score: 0
Accepted
time: 1327ms
memory: 226672kb

input:

9992

output:

433

result:

ok 1 number(s): "433"

Test #90:

score: 0
Accepted
time: 1334ms
memory: 226804kb

input:

9991

output:

425

result:

ok 1 number(s): "425"

Test #91:

score: 0
Accepted
time: 1325ms
memory: 226656kb

input:

9990

output:

509

result:

ok 1 number(s): "509"

Test #92:

score: 0
Accepted
time: 1345ms
memory: 226656kb

input:

9989

output:

808

result:

ok 1 number(s): "808"

Test #93:

score: 0
Accepted
time: 1329ms
memory: 226880kb

input:

9988

output:

734

result:

ok 1 number(s): "734"

Test #94:

score: 0
Accepted
time: 1344ms
memory: 226776kb

input:

9987

output:

922

result:

ok 1 number(s): "922"

Test #95:

score: 0
Accepted
time: 1353ms
memory: 226652kb

input:

9986

output:

1252

result:

ok 1 number(s): "1252"

Test #96:

score: 0
Accepted
time: 1329ms
memory: 226708kb

input:

9985

output:

378

result:

ok 1 number(s): "378"

Test #97:

score: 0
Accepted
time: 1322ms
memory: 226712kb

input:

9984

output:

472

result:

ok 1 number(s): "472"

Test #98:

score: 0
Accepted
time: 1350ms
memory: 226708kb

input:

9983

output:

363

result:

ok 1 number(s): "363"

Test #99:

score: 0
Accepted
time: 1362ms
memory: 226692kb

input:

9982

output:

1121

result:

ok 1 number(s): "1121"

Test #100:

score: 0
Accepted
time: 1385ms
memory: 226836kb

input:

9981

output:

261

result:

ok 1 number(s): "261"

Test #101:

score: 0
Accepted
time: 1412ms
memory: 226772kb

input:

9980

output:

228

result:

ok 1 number(s): "228"

Test #102:

score: 0
Accepted
time: 32ms
memory: 203688kb

input:

1811

output:

2

result:

ok 1 number(s): "2"

Test #103:

score: 0
Accepted
time: 362ms
memory: 211144kb

input:

5598

output:

14

result:

ok 1 number(s): "14"

Test #104:

score: 0
Accepted
time: 57ms
memory: 204472kb

input:

2466

output:

33

result:

ok 1 number(s): "33"

Extra Test:

score: 0
Extra Test Passed