QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#258120#7746. Go go Baron Bunny!ucup-team266#AC ✓71ms42136kbC++143.0kb2023-11-19 15:19:362023-11-19 15:19:39

Judging History

This is the latest submission verdict.

  • [2023-11-19 15:19:39]
  • Judged
  • Verdict: AC
  • Time: 71ms
  • Memory: 42136kb
  • [2023-11-19 15:19:36]
  • Submitted

answer

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef array<int, 3> ai3;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
const int Mod = 998244353;
const int inv[5] = {0, 1, (Mod+1) / 2, (Mod+1) / 3};
inline int sign(int a){ return (a&1) ? (Mod-1) : 1; }
inline void uadd(int &a, int b){ a += b-Mod; a += (a>>31) & Mod; }
inline void usub(int &a, int b){ a -= b, a += (a>>31) & Mod; }
inline void umul(int &a, int b){ a = (int)(1ll * a * b % Mod); }
inline int add(int a, int b){ a += b-Mod; a += (a>>31) & Mod; return a; }
inline int sub(int a, int b){ a -= b, a += (a>>31) & Mod; return a; }
inline int mul(int a, int b){ a = (int)(1ll * a * b % Mod); return a; }
int qpow(int b, int p){ int ret = 1; while(p){ if(p&1) umul(ret, b); umul(b, b), p >>= 1; } return ret; }
const int fN = 2000200;
int fact[fN], invfact[fN], pw2[fN], invpw2[fN];
void initfact(int n){
	pw2[0] = 1; for(int i = 1; i <= n; ++i) pw2[i] = mul(pw2[i-1], 2);
	invpw2[0] = 1; for(int i = 1; i <= n; ++i) invpw2[i] = mul(invpw2[i-1], (Mod+1) / 2);
	fact[0] = 1; for(int i = 1; i <= n; ++i) fact[i] = mul(fact[i-1], i);
	invfact[n] = qpow(fact[n], Mod-2); for(int i = n; i > 0; --i) invfact[i-1] = mul(invfact[i], i);
}
int binom(int n, int m){ return ((n == m) ? 1 : ((m < 0 || m > n) ? 0 : mul(fact[n], mul(invfact[m], invfact[n-m])))); }
const double pi = acos(-1);
inline void chmax(ll &a, ll b){ (b>a) ? (a=b) : 0; }
inline void chmin(ll &a, ll b){ (b<a) ? (a=b) : 0; }

ll N, K, T;

int n, tp0, s;
int f[2000200];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	initfact(2000020);

	cin >> N >> K >> T;
	if(K > 2000000 || (K-1) * K / 2 > N || K * (K+1) / 2 + K < N) return cout << "0\n", 0;

	if(K * (K+1) / 2 > N)
		n = (int)(K), tp0 = 1, s = (int)(N - (K-1) * K / 2);
	else 
		n = (int)(K+1), tp0 = 0, s = (int)(N - K * (K+1) / 2);

	//cout << n << " " << s << " " << tp0 << "\n";

	for(int l = 1; l <= n; ++l) if(n % l == 0){
		int cnt = n/l;
		if(s % cnt != 0) continue;
		int c1 = s / (cnt);
		for(int k = 0; k <= c1; ++k){
			int val1 = binom(c1 - 1, k - 1);
			if(!val1) continue;
			rep(tp1, 2){
				int val0 = binom(l - c1 - 1, k-1 + (!tp0) + (!tp1) - 1);
				if(!val0) continue;
				umul(val0, val1);
				//cout << "  " << l-c1-1 << " " << k-1 << "+" << (!tp0) << "+" << (!tp1) << "\n";
				int c10;
				if(tp0 && tp1) c10 = (k-1) * cnt;
				else if(tp0) c10 = k * cnt;
				else if(tp1) c10 = k * cnt - 1;
				else c10 = k * cnt;
				//cout << " " << l << " " << k << " " << tp1 << " " << val1 << " " << val0 << " " << c10 << "\n";
				uadd(f[l], mul(val0, mul(fact[K], invpw2[c10])));
			}
		}
		//cout << l << ": " << f[l] << "\n";
	}

	for(int i = 1; i <= n; ++i) if(n % i == 0) for(int j = i+i; j <= n; j += i) usub(f[j], f[i]);

	int ans = 0;
	for(int i = 1; i <= n; ++i) if(n % i == 0 && T % i == 0) uadd(ans, f[i]);
	cout << ans << "\n";
	
	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 34ms
memory: 36492kb

input:

2 1 2

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 30ms
memory: 35560kb

input:

8 4 2

output:

6

result:

ok 1 number(s): "6"

Test #3:

score: 0
Accepted
time: 34ms
memory: 36240kb

input:

29 7 154

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: 0
Accepted
time: 36ms
memory: 35448kb

input:

50 10 10

output:

77225400

result:

ok 1 number(s): "77225400"

Test #5:

score: 0
Accepted
time: 31ms
memory: 36080kb

input:

50 9 10

output:

11362680

result:

ok 1 number(s): "11362680"

Test #6:

score: 0
Accepted
time: 38ms
memory: 36224kb

input:

2 1 1

output:

0

result:

ok 1 number(s): "0"

Test #7:

score: 0
Accepted
time: 38ms
memory: 36684kb

input:

20 6 15

output:

0

result:

ok 1 number(s): "0"

Test #8:

score: 0
Accepted
time: 29ms
memory: 36068kb

input:

31 7 62

output:

0

result:

ok 1 number(s): "0"

Test #9:

score: 0
Accepted
time: 34ms
memory: 36172kb

input:

1 1 1

output:

1

result:

ok 1 number(s): "1"

Test #10:

score: 0
Accepted
time: 34ms
memory: 35948kb

input:

1 1 1000000000000

output:

1

result:

ok 1 number(s): "1"

Test #11:

score: 0
Accepted
time: 34ms
memory: 35256kb

input:

1000000 1414 999999999292

output:

626239238

result:

ok 1 number(s): "626239238"

Test #12:

score: 0
Accepted
time: 33ms
memory: 35736kb

input:

1000000 1413 999999999292

output:

804023673

result:

ok 1 number(s): "804023673"

Test #13:

score: 0
Accepted
time: 26ms
memory: 35148kb

input:

637704 1129 999999999368

output:

376288586

result:

ok 1 number(s): "376288586"

Test #14:

score: 0
Accepted
time: 34ms
memory: 36120kb

input:

777711 1246 999999999893

output:

315967293

result:

ok 1 number(s): "315967293"

Test #15:

score: 0
Accepted
time: 31ms
memory: 35868kb

input:

738077 1215 999999999405

output:

481429116

result:

ok 1 number(s): "481429116"

Test #16:

score: 0
Accepted
time: 38ms
memory: 35660kb

input:

878084 1324 999999999825

output:

85615210

result:

ok 1 number(s): "85615210"

Test #17:

score: 0
Accepted
time: 33ms
memory: 34940kb

input:

879744 1326 999999998712

output:

826681339

result:

ok 1 number(s): "826681339"

Test #18:

score: 0
Accepted
time: 34ms
memory: 36084kb

input:

519750 1019 999999999120

output:

380025867

result:

ok 1 number(s): "380025867"

Test #19:

score: 0
Accepted
time: 30ms
memory: 35796kb

input:

521410 1021 999999999509

output:

43307492

result:

ok 1 number(s): "43307492"

Test #20:

score: 0
Accepted
time: 34ms
memory: 36588kb

input:

578829 1075 999999999204

output:

847975635

result:

ok 1 number(s): "847975635"

Test #21:

score: 0
Accepted
time: 30ms
memory: 36344kb

input:

580490 1077 3

output:

0

result:

ok 1 number(s): "0"

Test #22:

score: 0
Accepted
time: 34ms
memory: 35968kb

input:

720496 1199 240

output:

0

result:

ok 1 number(s): "0"

Test #23:

score: 0
Accepted
time: 35ms
memory: 35324kb

input:

722157 1202 601

output:

952370308

result:

ok 1 number(s): "952370308"

Test #24:

score: 0
Accepted
time: 34ms
memory: 35948kb

input:

862163 1312 1313

output:

626393445

result:

ok 1 number(s): "626393445"

Test #25:

score: 0
Accepted
time: 29ms
memory: 36328kb

input:

822530 1283 1

output:

0

result:

ok 1 number(s): "0"

Test #26:

score: 0
Accepted
time: 30ms
memory: 36732kb

input:

962536 1386 1

output:

0

result:

ok 1 number(s): "0"

Test #27:

score: 0
Accepted
time: 30ms
memory: 36344kb

input:

1000000 1412 999999999292

output:

0

result:

ok 1 number(s): "0"

Test #28:

score: 0
Accepted
time: 30ms
memory: 35804kb

input:

1000000000 44721 999999975339

output:

510734471

result:

ok 1 number(s): "510734471"

Test #29:

score: 0
Accepted
time: 34ms
memory: 36068kb

input:

1000000000 44720 999999975339

output:

848193647

result:

ok 1 number(s): "848193647"

Test #30:

score: 0
Accepted
time: 25ms
memory: 35788kb

input:

842907373 41059 999999992564

output:

372008876

result:

ok 1 number(s): "372008876"

Test #31:

score: 0
Accepted
time: 34ms
memory: 34872kb

input:

509306715 31915 999999995252

output:

449159217

result:

ok 1 number(s): "449159217"

Test #32:

score: 0
Accepted
time: 34ms
memory: 36744kb

input:

724371023 38062 999999995226

output:

184015087

result:

ok 1 number(s): "184015087"

Test #33:

score: 0
Accepted
time: 26ms
memory: 36064kb

input:

890770366 42207 999999997728

output:

181797941

result:

ok 1 number(s): "181797941"

Test #34:

score: 0
Accepted
time: 34ms
memory: 36428kb

input:

900801961 42445 999999997945

output:

723246071

result:

ok 1 number(s): "723246071"

Test #35:

score: 0
Accepted
time: 26ms
memory: 35688kb

input:

567201303 33680 999999971049

output:

976667605

result:

ok 1 number(s): "976667605"

Test #36:

score: 0
Accepted
time: 23ms
memory: 35684kb

input:

782265611 39554 999999995722

output:

382214761

result:

ok 1 number(s): "382214761"

Test #37:

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

input:

743632241 38564 999999975555

output:

622113251

result:

ok 1 number(s): "622113251"

Test #38:

score: 0
Accepted
time: 27ms
memory: 35404kb

input:

753663836 38824 2

output:

0

result:

ok 1 number(s): "0"

Test #39:

score: 0
Accepted
time: 35ms
memory: 36220kb

input:

920063179 42896 181

output:

0

result:

ok 1 number(s): "0"

Test #40:

score: 0
Accepted
time: 34ms
memory: 36136kb

input:

635127486 35641 29

output:

0

result:

ok 1 number(s): "0"

Test #41:

score: 0
Accepted
time: 35ms
memory: 35572kb

input:

801526829 40037 40038

output:

966008245

result:

ok 1 number(s): "966008245"

Test #42:

score: 0
Accepted
time: 38ms
memory: 35712kb

input:

811558424 40288 4

output:

0

result:

ok 1 number(s): "0"

Test #43:

score: 0
Accepted
time: 27ms
memory: 36496kb

input:

977957767 44225 1134

output:

0

result:

ok 1 number(s): "0"

Test #44:

score: 0
Accepted
time: 30ms
memory: 35296kb

input:

1000000000 44719 999999975339

output:

0

result:

ok 1 number(s): "0"

Test #45:

score: 0
Accepted
time: 44ms
memory: 40664kb

input:

1000000000000 1414214 999999204684

output:

486279705

result:

ok 1 number(s): "486279705"

Test #46:

score: 0
Accepted
time: 48ms
memory: 42136kb

input:

1000000000000 1414213 999999204684

output:

480189439

result:

ok 1 number(s): "480189439"

Test #47:

score: 0
Accepted
time: 30ms
memory: 35424kb

input:

815496560693 811750096047 999999745266

output:

0

result:

ok 1 number(s): "0"

Test #48:

score: 0
Accepted
time: 29ms
memory: 36460kb

input:

582297122576 579821664123 999999766452

output:

0

result:

ok 1 number(s): "0"

Test #49:

score: 0
Accepted
time: 58ms
memory: 39936kb

input:

554379675168 1052976 999999724464

output:

850999094

result:

ok 1 number(s): "850999094"

Test #50:

score: 0
Accepted
time: 54ms
memory: 39676kb

input:

825475204348 1284892 999998814682

output:

718965161

result:

ok 1 number(s): "718965161"

Test #51:

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

input:

801852724236 1266375 999999350625

output:

266617066

result:

ok 1 number(s): "266617066"

Test #52:

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

input:

568653286119 1066445 999998949078

output:

268095321

result:

ok 1 number(s): "268095321"

Test #53:

score: 0
Accepted
time: 47ms
memory: 39752kb

input:

540735838711 1039938 999999181110

output:

955131707

result:

ok 1 number(s): "955131707"

Test #54:

score: 0
Accepted
time: 63ms
memory: 40104kb

input:

807536400595 1270854 999998944705

output:

83358005

result:

ok 1 number(s): "83358005"

Test #55:

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

input:

779618953187 1248694 624347

output:

695027909

result:

ok 1 number(s): "695027909"

Test #56:

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

input:

546419515070 1045388 1

output:

0

result:

ok 1 number(s): "0"

Test #57:

score: 0
Accepted
time: 50ms
memory: 39984kb

input:

527092002255 1026735 342245

output:

168868859

result:

ok 1 number(s): "168868859"

Test #58:

score: 0
Accepted
time: 46ms
memory: 40348kb

input:

793892564138 1260072 1

output:

0

result:

ok 1 number(s): "0"

Test #59:

score: 0
Accepted
time: 46ms
memory: 41244kb

input:

765975116731 1237720 44

output:

0

result:

ok 1 number(s): "0"

Test #60:

score: 0
Accepted
time: 41ms
memory: 39288kb

input:

532775678613 1032254 11865

output:

0

result:

ok 1 number(s): "0"

Test #61:

score: 0
Accepted
time: 34ms
memory: 35008kb

input:

1000000000000 1414212 999999204684

output:

0

result:

ok 1 number(s): "0"

Extra Test:

score: 0
Extra Test Passed